从事安卓开发也有三年了,一直在借鉴别人的东西,这还是第一次写博客。写的不好敬请见谅!
最近遇到一个需求,listview下拉刷新,以及上滑加载等。 网上找了许多参考资料,最终采用的是Swiperefreshlayout中嵌套listview。分页加载数据、上滑加载都搞定了,卡在下拉刷新时view跟着下移,以及下拉刷新时listview还可滑动导致的问题。
下拉刷新view跟着下移通过自定义Swiperefreshlayout最终解决了,但是下拉刷新时禁止listview滑动遇到了关卡。网上搜索了许多资料,有的说setEnabled(false),也有的说自定义listview拦截事件,都试过了,均无效。(也许是我个人没写正确)
今天突然想到,让listview失去焦点是不是可以呢?找了一下,单纯的属性好像是没有的,于是在外面套一层FrameLayout,里面嵌套了一个Swiperefreshlayout,与一个linearlayout(linearlayout中有一个edittext)然后Swiperefreshlayout中嵌套listview。初始的时候默认linearlayout不可见。当你需要禁止listview滑动或者Swiperefreshlayout滑动时设置linearlayout可见。这时候LinearLayout布局就将焦点拿走了。Swiperefreshlayout与listview均不可滑动!就解决了!一直借鉴别人的东西,脑子都生锈了,以后要多多写博客。希望对大家有用,下面贴上布局代码:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.nankang.gis.landpatrol.view.CustomSwiperefreshlayout android:id="@+id/swipe_refresh_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/messageList" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="10dp" android:cacheColorHint="@color/color_transparent" android:divider="@null" android:dividerHeight="0dp" android:fadingEdge="none" android:isScrollContainer="false" android:listSelector="@color/color_transparent" android:overScrollMode="never" android:scrollbars="none" /> </com.nankang.gis.landpatrol.view.CustomSwiperefreshlayout> <LinearLayout android:id="@+id/layout_listview_not_scroll" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:visibility="gone"> <EditText android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </FrameLayout>
希望对大家有所帮助,转载请注明:https://blog.youkuaiyun.com/qq_28189795/article/details/80235277