Android中SwipeRefreshLayout和listview的冲突解决办法
来源:互联网 发布:赫连勃勃大王知乎 编辑:程序博客网 时间:2024/06/08 15:10
SwipeRefreshLayout和listview的冲突解决办法
在google放出了SwipeRefreshLayout之后,就再也不用辛辛苦苦的用上百行代码来实现下拉刷新了(不过还是需要理解透彻以前版本的下拉刷新是如何实现的),在用的过程中,为了使我们的程序更加的好看,大家肯定想过把各种能滑动的东西结合起来,swiperefreshlayout和listview或者是可以滑动的scrollview结合起来的时候,不免也碰到了冲突的问题.
现在就来奉上一种处理冲突的方法,先上一段使用swiperefreshlayout的代码.....
<android.support.v4.widget.SwipeRefreshLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:id="@+id/swipe"> <ListView android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Random number:" android:id="@+id/lbl"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/rndNum" android:layout_toRightOf="@id/lbl"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/lbl" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:text="Swipe to Refresh" style="@android:style/TextAppearance.Medium"/> </RelativeLayout> </ListView></android.support.v4.widget.SwipeRefreshLayout>
... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); final TextView rndNum = (TextView) findViewById(R.id.rndNum); swipeView.setColorScheme(android.R.color.holo_blue_dark, android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_green_light); swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeView.setRefreshing(true); Log.d("Swipe", "Refreshing Number"); ( new Handler()).postDelayed(new Runnable() { @Override public void run() { swipeView.setRefreshing(false); double f = Math.random(); rndNum.setText(String.valueOf(f)); } }, 3000); } }); }....
这样的话,在里面直接上一个listview会和swiperefreshlayout的下拉刷新冲突,怎么样解决这个问题呢?先说一下思路,在listview向下各种滚动的过程中,可以加上一个OnScrollListener,监听listview是否滑到了最顶端的一个item,如果在最顶端,就将swiperefreshlayout设置成setEnabled(true),如果不再最顶端,就设置成setEnabled(false),这样就可以阻止冲突了~~~~~~其他的也可以模仿这种处理形式...
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final SwipeRefreshLayout swipeView = (SwipeRefreshLayout) findViewById(R.id.swipe); swipeView.setEnabled(false); ListView lView = (ListView) findViewById(R.id.list); ArrayAdapter<String> adp = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, createItems(40,0 )); lView.setAdapter(adp); swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeView.setRefreshing(true); ( new Handler()).postDelayed(new Runnable() { @Override public void run() { swipeView.setRefreshing(false); } }, 3000); } }); lView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem == 0) swipeView.setEnabled(true); else swipeView.setEnabled(false); } });}
3 0
- Android中SwipeRefreshLayout和listview的冲突解决办法
- Android 解决SwipeRefreshLayout和listview的setEmptyView的冲突 listview和scrollview的冲突
- ListView和SwipeRefreshLayout的滑动冲突
- Android SwipeRefreshLayout教程 [更好的解决ListView SwipeRefreshLayout 冲突]
- Android 解决SwipeRefreshLayout与ListView和ScrollView滑动冲突
- SwipeRefreshLayout和ListView的EmptyView共存冲突的问题
- SwipeRefreshLayout和ListView的EmptyView共存冲突的问题
- Android问题集(3):SwipeRefreshLayout与ListView的滑动冲突
- Android SwipeRefreshLayout和RecyclerView嵌套时 下拉刷新冲突的解决办法
- SwipeRefreshLayout 与ListView滑动冲突的解决
- Android中SwipeRefreshLayout和ViewPager左右滑动冲突的原因以及正确的解决方法
- 关于ListView和ViewPager冲突的解决办法
- Android 中listview 和scrollview 滚动冲突事件的解决方法
- 优雅的解决SwipeRefreshLayout和ListView的EmptyView共存冲突的问题(全网独创)
- Android之SwipeRefreshLayout使用和冲突解决
- 使用Android Supportv4 SwipeRefreshLayout有关ListView滑动冲突问题
- Android 自定义SwipeRefreshLayout与ListView、ScrollView滑动兼容冲突
- 横向Listview,viewpager,RecyclerView中与swiperefreshlayout滑动冲突
- HDU2212 DFS【水题】【打表】
- 让Angularjs外面表单忽略对内嵌表单的校验
- 1023. Have Fun with Numbers (20)
- iOS视图切换动画
- 1024. Palindromic Number (25)
- Android中SwipeRefreshLayout和listview的冲突解决办法
- Raspberry Pi -- Cross Compiling on Mac OSX
- WCF学习之基本概念的理解
- Android 控制ScrollView滚动到底部
- WV.28-大数阶乘算法8-入门篇之三汇编的威力
- Swift 登录页面跳转,条件判断 ,页面跳转
- 壳蓝冗佣诸业进楼枕窑遂常怔哪痕
- 按钮组件初步
- 1025. PAT Ranking (25)