【发布时间】:2020-04-18 21:58:04
【问题描述】:
我已经实现了一个手势来提示用户我们在 iOS 应用中拥有的滑动选项。它看起来像-
我是 Android 应用开发的新手。我已经实现了除了动画之外的所有东西,比如屏幕。如何在 Android 应用程序中为回收站视图项添加相同的动画?
【问题讨论】:
标签: android android-animation android-recyclerview
我已经实现了一个手势来提示用户我们在 iOS 应用中拥有的滑动选项。它看起来像-
我是 Android 应用开发的新手。我已经实现了除了动画之外的所有东西,比如屏幕。如何在 Android 应用程序中为回收站视图项添加相同的动画?
【问题讨论】:
标签: android android-animation android-recyclerview
最后,我自己实现了。
这里是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();
}
}
希望这对某人有所帮助!
【讨论】:
if (position == 4) { 时,动画就会起作用。