am 2d719d6c: AnimatedRecyclerActivity demo supports simpler RV item animations
* commit '2d719d6c716e4b800c9b9bcd31fe36fdddb8adfd': AnimatedRecyclerActivity demo supports simpler RV item animations
This commit is contained in:
@@ -6,6 +6,11 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/enableAnimations"
|
android:id="@+id/enableAnimations"
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
@@ -13,6 +18,15 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/enablePredictiveAnimations"
|
||||||
|
android:checked="true"
|
||||||
|
android:text="@string/enablePredictiveAnimations"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -103,8 +103,9 @@
|
|||||||
<string name="checkbox_layout_dir">Layout Dir</string>
|
<string name="checkbox_layout_dir">Layout Dir</string>
|
||||||
<string name="checkbox_stack_from_end">Stack From End</string>
|
<string name="checkbox_stack_from_end">Stack From End</string>
|
||||||
<string name="enableAnimations">Animate Changes</string>
|
<string name="enableAnimations">Animate Changes</string>
|
||||||
|
<string name="enablePredictiveAnimations">Predictive Animations</string>
|
||||||
<string name="add_item">Add</string>
|
<string name="add_item">Add</string>
|
||||||
<string name="delete_item">Delete</string>
|
<string name="delete_item">Del</string>
|
||||||
<string name="add_delete_item">A+D</string>
|
<string name="add_delete_item">A+D</string>
|
||||||
<string name="delete_add_item">D+A</string>
|
<string name="delete_add_item">D+A</string>
|
||||||
<string name="d1a2d3">d1a2d3</string>
|
<string name="d1a2d3">d1a2d3</string>
|
||||||
|
|||||||
@@ -45,9 +45,8 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
ArrayList<String> mItems = new ArrayList<String>();
|
ArrayList<String> mItems = new ArrayList<String>();
|
||||||
MyAdapter mAdapter;
|
MyAdapter mAdapter;
|
||||||
|
|
||||||
static final boolean USE_CUSTOM_ANIMATIONS = false;
|
|
||||||
|
|
||||||
boolean mAnimationsEnabled = true;
|
boolean mAnimationsEnabled = true;
|
||||||
|
boolean mPredictiveAnimationsEnabled = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -74,6 +73,15 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
mAnimationsEnabled = isChecked;
|
mAnimationsEnabled = isChecked;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CheckBox enablePredictiveAnimations =
|
||||||
|
(CheckBox) findViewById(R.id.enablePredictiveAnimations);
|
||||||
|
enablePredictiveAnimations.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
mPredictiveAnimationsEnabled = isChecked;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -158,8 +166,8 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsItemAnimations() {
|
public boolean supportsPredictiveItemAnimations() {
|
||||||
return mAnimationsEnabled;
|
return mPredictiveAnimationsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -186,17 +194,18 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
View v = recycler.getViewForPosition(mFirstPosition + i);
|
View v = recycler.getViewForPosition(mFirstPosition + i);
|
||||||
|
|
||||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) v.getLayoutParams();
|
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) v.getLayoutParams();
|
||||||
if (!params.isItemRemoved()) {
|
if (!mPredictiveAnimationsEnabled || !params.isItemRemoved()) {
|
||||||
addView(v);
|
addView(v);
|
||||||
}
|
}
|
||||||
measureChild(v, 0, 0);
|
measureChild(v, 0, 0);
|
||||||
bottom = top + v.getMeasuredHeight();
|
bottom = top + v.getMeasuredHeight();
|
||||||
v.layout(left, top, right, bottom);
|
v.layout(left, top, right, bottom);
|
||||||
if (params.isItemRemoved()) {
|
if (mPredictiveAnimationsEnabled && params.isItemRemoved()) {
|
||||||
parentBottom += v.getHeight();
|
parentBottom += v.getHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mAnimationsEnabled && mPredictiveAnimationsEnabled) {
|
||||||
// Now that we've run a full layout, figure out which views were not used
|
// Now that we've run a full layout, figure out which views were not used
|
||||||
// (cached in previousViews). For each of these views, position it where
|
// (cached in previousViews). For each of these views, position it where
|
||||||
// it would go, according to its position relative to the visible
|
// it would go, according to its position relative to the visible
|
||||||
@@ -227,6 +236,7 @@ public class AnimatedRecyclerView extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
|
public RecyclerView.LayoutParams generateDefaultLayoutParams() {
|
||||||
|
|||||||
Reference in New Issue
Block a user