您好,登錄后才能下訂單哦!
本篇文章為大家展示了在android項目中使用SwipeRefreshLayout組件實現下拉小球式刷新功能,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
swiperefreshlayout實現下拉小球式的刷新,供大家參考,具體內容如下
布局文件:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content"> </ListView> </android.support.v4.widget.SwipeRefreshLayout> </RelativeLayout>
MainActivity:
public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener{ private static final int REFRESH_STATUS =0; private ListView myListView; private SwipeRefreshLayout mySwipeRefreshLayout; private ArrayAdapter<String> listAdapter; private List<String> listIDE = new ArrayList<String>(Arrays.asList("Visual Studio", "Android Studio", "Eclipse", "Xcode")); private Handler refreshHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case REFRESH_STATUS: listIDE.removeAll(listIDE); listIDE.addAll(Arrays.asList("C#", "Java", "C++","Object-C")); listAdapter.notifyDataSetChanged(); mySwipeRefreshLayout.setRefreshing(false); break; } }; }; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myListView = (ListView) findViewById(R.id.listView); mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); mySwipeRefreshLayout.setOnRefreshListener(this); mySwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); listAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,listIDE); myListView.setAdapter(listAdapter); } @Override public void onRefresh() { refreshHandler.sendEmptyMessageDelayed(REFRESH_STATUS, 1500); } }
效果圖:
上述內容就是在android項目中使用SwipeRefreshLayout組件實現下拉小球式刷新功能,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。