直播平臺製作,SwipeRefreshLayout下拉重新整理的用法

zhibo系統開發發表於2023-09-27

直播平臺製作,SwipeRefreshLayout下拉重新整理的用法

佈局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="
    xmlns:tools="
    xmlns:app="
    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下拉重新整理的用法, 更多內容歡迎關注之後的文章 


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2986292/,如需轉載,請註明出處,否則將追究法律責任。

相關文章