我想用listView实现滚动刷新功能.此外,如果列表为空,则在同一布局文件中还有其他视图元素.这是我的布局文件.问题是,当我向下滚动然后尝试向上滚动时,而不是一直滚动到顶部然后刷新它只是在那里刷新并向上滚动不起作用.
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="64dp"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/inbox_empty" />
<TextView
android:id="@+id/noEventsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@+id/noEventsIcon" />
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_alignParentBottom="true"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="@color/dividerOnBlack" />
</RelativeLayout>
<ListView
android:id="@+id/list_items"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:cacheColorHint="@android:color/transparent"
android:choiceMode="multipleChoice"
android:descendantFocusability="afterDescendants"
android:divider="@android:color/transparent"
android:dividerHeight="0px"
android:scrollbars="none" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的onScroll方法.
@Override
public void onScroll(AbsListView view,int firstVisibleItem,int visibleItemCount,int totalItemCount) {
// If the total item count is zero and the previous isn't, assume the …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现这个播放器动画
我还希望能够在折叠和展开时滑动歌曲。所以我们的想法是将 aMotionLayout与 a一起使用RecyclerView,并且还有RecyclerViewbe a 的每个项目MotionLayout。通过这种方式,我可以在 上应用展开动画,RecyclerView并在其子项上应用过渡。
如所附视频所示,过渡本身运行良好。但是让阻力作用于它RecyclerView本身并没有。仅当触摸从 外部开始时才会检测到拖动,RecyclerView如视频中突出显示的触摸所示,其中触摸从 下方开始RecyclerView。
如果在 上开始触摸RecyclerView,则歌曲的滚动会消耗该事件。即使禁用附件LinearLayoutManager中的滚动也不起作用。我还尝试覆盖onTouch以RecyclerView使其始终返回false并且不消耗任何触摸事件(理论上),但这也不起作用。
该项目可以在这里找到https://github.com/vlatkozelka/PlayerAnimation2 它并不意味着成为一个生产就绪的应用程序,只是一个测试游乐场。
这是相关的代码
布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
app:layoutDescription="@xml/player_scene"
tools:context=".MainActivity"
android:id="@+id/layout_main"
>
<FrameLayout
android:id="@+id/layout_player"
android:layout_width="match_parent"
android:layout_height="@dimen/mini_player_height"
android:elevation="2dp"
app:layout_constraintBottom_toTopOf="@id/layout_navigation"
app:layout_constraintStart_toStartOf="parent"
android:background="@color/dark_grey"
android:focusable="true"
android:clickable="true"
>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_songs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:clickable="false"
/>
</FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_navigation"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-animation android-recyclerview android-motionlayout
我遇到了视图未刷新的问题MotionLayout。
似乎在某些时候,刷新/重绘机制MotionLayout被破坏,子视图(包括嵌套视图)在屏幕上更新自身时出现随机问题。到目前为止我所经历的:
RecyclerView有时不刷新。当新数据可用时会发生这种情况,我正在使用分页库来填充数据。当我在那里得到新数据时,我用滚动 1 个像素的解决方法修复了它 - recyclerView.smoothScrollBy(0,1)。之后,RecyclerView开始重新绘制自己就好了。EditText向官方添加一个来重现所有这些MotionLayout示例我遇到的问题的一些示例:\n\nTextInputLayoutwith app:endIconMode="clear_text"in MotionLayout -> ConstraintLayout -> TextInputLayout,X当我开始打字时(也在关闭键盘后),有时不会显示该按钮。TextView部分重绘!我在 a 中显示文本"No Results",并根据某种逻辑在它们之间切换,但不是刷新整个文本,而是仅显示在 UI 中。我已经调试过它,布局检查器说一切都很好,文本视图值为,但我在屏幕上看不到它。"No Posts"TextView"No""No Results"SwipeRefreshLayout重要提示:当我进行转换时,所有刷新/重画问题都已解决!当我遇到一些混乱的状态,其中 3 个嵌套子视图被冻结/部分绘制时,我只需要按下一个按钮来触发我的转换,并且所有这些子视图都会愉快地重新绘制自己!
\n\n请告诉我这是否是一个已知问题以及是否有解决方法。我也许可以做不可见的 1 像素转换,但我什至无法检测到MotionLayout刷新何时被破坏,处理键盘和新数据RecyclerView似乎并没有涵盖所有情况。否则,我将不得不返回ConstraintLayout并考虑OnSwipe …
当 RecyclerView 向上拖动时,我使用 MotionLayout 来实现一些很酷的效果,但看起来当我想将 SwipeRefreshLayout 与 RecyclerView 一起使用时,事情会发生冲突。
如果没有 SwipeRefreshLayout,那很好
如果我用 SwipeRefreshLayout 包围,向上拖动的行为就像反对一样奇怪
https://gist.github.com/GHChrisSu/6aadf40dc693bc47cbb83a167a82a4b9
运动场景如下
https://gist.github.com/GHChrisSu/a154d59f34555cccfc1b48617989ae16
android swiperefreshlayout android-recyclerview android-motionlayout