SwipeRefreshLayout控件使用方法

android.support.v4.widget.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">
<ScrollView
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>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>



java代码:

finalSwipeRefreshLayoutswipeView=(SwipeRefreshLayout)findViewById(R.id.swipe);finalTextViewrndNum=(TextView)findViewById(R.id.rndNum);//设置刷新颜色swipeView.setColorSchemeResources(android.R.color.holo_blue_light);//设置刷新监听器swipeView.setOnRefreshListener(newSwipeRefreshLayout.OnRefreshListener(){@OverridepublicvoidonRefresh(){swipeView.setRefreshing(true);Log.d("Swipe","RefreshingNumber");//Handler更新界面,延时3000毫秒(newHandler()).postDelayed(newRunnable(){@Overridepublicvoidrun(){//设置刷新结束swipeView.setRefreshing(false);doublef=Math.random();rndNum.setText(String.valueOf(f));}},3000);}});




实现效果:



SwipeRefreshLayoutDemo



更多相关文章

  1. Android中设置全屏的方法
  2. Android(安卓)去掉title bar的3个方法
  3. Android中设置全屏的方法
  4. android之渐变色背景
  5. Android(安卓)跳转+两种ListView+ListheaderView
  6. android 横屏 竖屏 全屏 当前屏幕宽 高
  7. Android中自动跳转到系统设置界面
  8. TabLayout 设置指示器宽度问题
  9. 自定义Android标题栏

随机推荐

  1. android优化 清除无效代码 UCDetector
  2. android下使用gdb调试工具笔记
  3. android启动过程详解(一)——解析init.rc
  4. android notification通知栏及8.0适配
  5. 修正Android摄像头API
  6. 通过Ant将android project打包成apk并安
  7. android按键驱动开发实例1(修改一个按键)
  8. android的学习记录-包括android的安装、
  9. Android Studio安装配置(详细版)
  10. Android 各版本 设置 USB 默认连接 MTP