Skip to content

Commit 4d85b47

Browse files
committed
Reduce overdraws
1 parent f5d660e commit 4d85b47

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

example/src/main/java/com/h6ah4i/android/example/advrecyclerview/demo_s_button/SwipeableWithButtonExampleAdapter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.view.ViewGroup;
2424
import android.widget.Button;
2525
import android.widget.FrameLayout;
26+
import android.widget.RelativeLayout;
2627
import android.widget.TextView;
2728

2829
import com.h6ah4i.android.example.advrecyclerview.R;
@@ -60,12 +61,14 @@ public interface EventListener {
6061

6162
public static class MyViewHolder extends AbstractSwipeableItemViewHolder {
6263
public FrameLayout mContainer;
64+
public RelativeLayout mBehindViews;
6365
public TextView mTextView;
6466
public Button mButton;
6567

6668
public MyViewHolder(View v) {
6769
super(v);
6870
mContainer = (FrameLayout) v.findViewById(R.id.container);
71+
mBehindViews = (RelativeLayout) v.findViewById(R.id.behind_views);
6972
mTextView = (TextView) v.findViewById(android.R.id.text1);
7073
mButton = (Button) v.findViewById(android.R.id.button1);
7174
}
@@ -188,6 +191,11 @@ public int onGetSwipeReactionType(MyViewHolder holder, int position, int x, int
188191

189192
@Override
190193
public void onSetSwipeBackground(MyViewHolder holder, int position, int type) {
194+
if (type == Swipeable.DRAWABLE_SWIPE_NEUTRAL_BACKGROUND) {
195+
holder.mBehindViews.setVisibility(View.GONE);
196+
} else {
197+
holder.mBehindViews.setVisibility(View.VISIBLE);
198+
}
191199
}
192200

193201
@Override

example/src/main/java/com/h6ah4i/android/example/advrecyclerview/demo_s_viewpager/ViewPagerSwipeableExampleAdapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.h6ah4i.android.example.advrecyclerview.demo_s_viewpager;
1818

19+
import android.graphics.Color;
20+
import android.support.v4.content.ContextCompat;
1921
import android.support.v4.view.ViewCompat;
2022
import android.support.v7.widget.RecyclerView;
2123
import android.util.Log;
@@ -130,6 +132,11 @@ public int onGetSwipeReactionType(MyViewHolder holder, int position, int x, int
130132

131133
@Override
132134
public void onSetSwipeBackground(MyViewHolder holder, int position, int type) {
135+
if (type == Swipeable.DRAWABLE_SWIPE_NEUTRAL_BACKGROUND) {
136+
holder.itemView.setBackgroundColor(Color.TRANSPARENT);
137+
} else {
138+
holder.itemView.setBackgroundColor(ContextCompat.getColor(holder.itemView.getContext(), R.color.bg_swipe_item_gray));
139+
}
133140
}
134141

135142
@Override

example/src/main/res/layout/list_item_view_pager.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
xmlns:android="http://schemas.android.com/apk/res/android"
2121
xmlns:tools="http://schemas.android.com/tools"
2222
android:layout_width="match_parent"
23-
android:layout_height="@dimen/list_item_height"
24-
android:background="@color/bg_swipe_item_gray">
23+
android:layout_height="@dimen/list_item_height">
2524

2625
<com.h6ah4i.android.example.advrecyclerview.demo_s_viewpager.PagerSwipeItemFrameLayout
2726
android:id="@+id/container"
2827
android:layout_width="match_parent"
2928
android:layout_height="match_parent"
30-
android:background="#ffffff"
29+
android:background="@color/bg_item_normal_state"
3130
android:clickable="true"
3231
android:foreground="?attr/selectableItemBackground">
3332

example/src/main/res/layout/list_item_with_leave_behind_button.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
xmlns:android="http://schemas.android.com/apk/res/android"
2121
xmlns:tools="http://schemas.android.com/tools"
2222
android:layout_width="match_parent"
23-
android:layout_height="64dp"
24-
android:background="@drawable/bg_swipe_item_neutral">
23+
android:layout_height="64dp">
2524

2625
<RelativeLayout
26+
android:id="@+id/behind_views"
2727
android:layout_width="match_parent"
2828
android:layout_height="match_parent"
29-
android:background="#888888">
29+
android:background="@color/bg_swipe_item_gray"
30+
android:visibility="gone"
31+
tools:visibility="visible">
3032

3133
<Button
3234
android:id="@android:id/button1"
@@ -45,7 +47,7 @@
4547
android:id="@+id/container"
4648
android:layout_width="match_parent"
4749
android:layout_height="match_parent"
48-
android:background="#ffffff"
50+
android:background="@color/bg_item_normal_state"
4951
android:clickable="true"
5052
android:foreground="?attr/selectableItemBackground"
5153
tools:visibility="invisible">

0 commit comments

Comments
 (0)