繁体   English   中英

动画回收器从左到右查看项目以告诉用户滑动选项

[英]Animate recycler view items left-right to tell user of swipe options

我已经实现了一个手势来提示用户我们在 iOS 应用程序中的滑动选项。 它看起来像-

在此处输入图片说明

我是 Android 应用程序开发的新手。 我已经实现了除动画之外的所有内容,例如屏幕。 如何在 Android 应用程序中为回收者视图项添加相同的动画?

最后,我自己实现了。

这是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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM