0
私はrecyclerview項目をアニメーション化するためのチュートリアルに従っていますが、アニメーションが適用されているかどうかは分かりません。Recyclerの表示項目でアニメーションが機能しない
Activity.Java: 更新されたコードはここにいた私は、ボタンのクリックで試してみましたが、私は、アダプタに
private void setupRecyclerView() {
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
final LayoutAnimationController controller =
AnimationUtils.loadLayoutAnimation(this, R.anim.layout_animation);
recyclerView.setLayoutAnimation(controller);
recyclerView.setAdapter(specialistListAdapter);
}
//placed a dummy button onclick to check animation working or not
public void reloadData(View view) {
runLayoutAnimation(recyclerView);
}
private void runLayoutAnimation(final RecyclerView recyclerView) {
final Context context = recyclerView.getContext();
final LayoutAnimationController controller =
AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation);
recyclerView.setLayoutAnimation(controller);
recyclerView.getAdapter().notifyDataSetChanged();
recyclerView.scheduleLayoutAnimation();
}
layout_animation.xmlを形成onBindHolderからアニメーションのメソッドを呼び出す方法を知りません:
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/item_list_animation"
android:delay="15%"
android:animationOrder="normal"
/>
item_list_animation.xml:
0事前に<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="-20%"
android:toYDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
/>
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:interpolator="@android:anim/decelerate_interpolator"
/>
<scale
android:fromXScale="105%"
android:fromYScale="105%"
android:toXScale="100%"
android:toYScale="100%"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="@android:anim/decelerate_interpolator"
/>
</set>
おかげ
runLayoutAnimation関数で見ることができるアニメーションがプログラムで読み込まれましたが、どのようにonBindViewHolderのメソッドを呼び出すのですか? –
実行するアクションがあるときはいつでもonBindViewholderでそのメソッドを呼び出す必要があります。 onclickListenerで行を削除したい場合は、その行を呼び出す必要があります。 – Anonymous
また、アダプタのリサイクラビューオブジェクトは必要ありません。yourViewHolder.itemView.getContext();のようなコンテキストを取得できます。 – Anonymous