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. Android4.1 Rotation 小结
  2. Android(安卓)EditText达到SearchView的效果
  3. Android(安卓)Studio设置类代码模板
  4. android通过反射来获取系统属性SystemProperties
  5. 设置默认来电铃声 android
  6. Gps简单更新
  7. android之Notification的使用
  8. Android(安卓)自定义AlertDialog 并且4个角为圆角
  9. Android初级教程调用手机拍照与摄像功能

随机推荐

  1. 分享golang实现文件传输小demo
  2. go语言中run与build命令的区别是什么?
  3. 解决GO语言安装air框架时遇到go: inconsi
  4. 分享5种文件变更时自动重载Go程序的方法
  5. go语言中普通函数与方法的区别是什么?
  6. golang中方法的receiver为指针和不为指针
  7. 分享一次腾讯Go开发岗位面试经过
  8. go是什么语言
  9. 详解Golang如何对excel进行处理
  10. 关于go值传递和地址传递的例子