直播平台制作,SwipeRefreshLayout下拉刷新的用法
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/swipe_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="要刷新的布局"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
MainActivity
public class MainActivity extends AppCompatActivity {
private SwipeRefreshLayout swipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeRefreshLayout=findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.teal_200));//设置刷新转圈的颜色
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.purple_200));//设置刷新的背景颜色
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh(){//刷新的处理事件
//假设两秒后停止刷新
//开启子线程
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
swipeRefreshLayout.setRefreshing(false);//停止刷新
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
});
}
}
以上就是直播平台制作,SwipeRefreshLayout下拉刷新的用法, 更多内容欢迎关注之后的文章
标签:SwipeRefreshLayout,layout,下拉,swipeRefreshLayout,直播,刷新,android,id From: https://www.cnblogs.com/yunbaomengnan/p/17732578.html