左右动画回收器视图项目以告诉用户滑动选项
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();
}
}
希望这对某人有所帮助!
我已经实现了一个手势来提示用户我们在 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();
}
}
希望这对某人有所帮助!