[英]Animate recycler view items left-right to tell user of swipe options
最后,我自己实现了。
这是item_layout.xml
-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="@+id/leftView"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignTop="@+id/main_layout"
android:layout_alignBottom="@id/main_layout"
android:layout_alignParentStart="true"
android:background="@color/darkGray" />
<View
android:id="@+id/rightView"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignTop="@+id/main_layout"
android:layout_alignBottom="@+id/main_layout"
android:layout_alignParentEnd="true"
android:background="@color/darkRed" />
<RelativeLayout id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
</RelativeLayout>
这是RecyclerView.Adapter
实现-
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
....
....
if (position == 0) {
ObjectAnimator animationLeft = ObjectAnimator.ofFloat(holder.swipeLayout, "translationX", 0f, 80f, 0f, -80f, 0f);
animationLeft.setDuration(1500);
animationLeft.start();
}
}
希望这可以帮助某人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.