我有这样的事情:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="cntxt">
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Title -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:gravity="center"
android:padding="20dp"
android:text="@string/title"
android:textColor="@android:color/white"
android:textSize="17sp" />
<!-- Recycler -->
<CustomRecyclerView
android:id="@+id/main_activity_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:scrollingCache="false" />
</LinearLayout>
当布局滚动到顶部时,当用户用他的手指进行类似“刷卡刷新”的移动时,我需要在Y轴上进行平移动画。换句话说,如果回收器在顶部,我需要跟随整个回收器的手指移动。
我试图将onTouch监听器附加到回收器,但回收器的内部滚动使情况不清楚。有什么想法来实现这个动画吗?
如果我将onTouchListener附加到main_layout并从iner文本视图执行操作,则动画将正常播放。但当我触摸回收器时没有任何反应(除了回收器的内部卷轴),请提前感谢您。
使最外层为a
SwipeRefreshLayout
而不是相对布局。这将为您提供任何方式的刷新功能。
另请注意,在提到的滑动布局下,只能有一个直接的子视图,所以你放置的东西......确保把它放在你拥有的线性布局中。
您可以附加OnRefreshListener来监听刷新布局的拉动。