动画回收器从左到右查看项目以告诉用户滑动选项 [英] Animate recycler view items left-right to tell user of swipe options
本文介绍了动画回收器从左到右查看项目以告诉用户滑动选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经实现了一个手势来提示用户我们在 iOS 应用中的滑动选项.它看起来像-
I have implemented a gesture to hint user of the swipe options that we have in our iOS app. Its looking like-
我是 Android 应用开发的新手.我已经实现了除动画之外的所有内容,例如屏幕.如何在 Android 应用程序中为回收站视图项添加相同的动画?
I am new to Android app development. I have implemented everything like the screen except the animation. How do I add same animation in Android application for recycler view items?
推荐答案
最后,我自己实现了.
这里是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();
}
}
希望这对某人有所帮助!
Hope this helps someone!
这篇关于动画回收器从左到右查看项目以告诉用户滑动选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文