SwipeRefreshLayout下拉重新整理,swiperefreshlayout

來源:互聯網
上載者:User

SwipeRefreshLayout下拉重新整理,swiperefreshlayout

1.SwipeRefreshLayout是Google在support v4 19.1版本的library更新的一個下拉重新整理組件,實現重新整理效果更方便。

弊端:只有下拉 

//設定重新整理控制項圈圈的顏色swipe_refresh_layout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_orange_light, android.R.color.holo_red_light, android.R.color.holo_green_light);//設定重新整理控制項背景色swipe_refresh_layout.setProgressBackgroundColorSchemeColor(getResources().getColor(android.R.color.white));//設定滑動距離swipe_refresh_layout.setDistanceToTriggerSync(100);//設定大小模式swipe_refresh_layout.setSize(SwipeRefreshLayout.DEFAULT);//設定下拉重新整理控制項狀態隱藏swipe_refresh_layout.setRefreshing(false);

  

2.在xml檔案中引用android.support.v4.widget.SwipeRefreshLayout控制項,在裡面可以放置任何一個控制項,例如ListView,gridview等。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="match_parent" >        <android.support.v4.widget.SwipeRefreshLayout          android:id="@+id/id_swipe_ly"          android:layout_width="match_parent"          android:layout_height="match_parent" >            <ListView              android:id="@+id/id_listview"              android:layout_width="match_parent"              android:layout_height="match_parent" >          </ListView>      </android.support.v4.widget.SwipeRefreshLayout>    </RelativeLayout> 

 

3.Java代碼

public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {private SwipeRefreshLayout swipeLayout;private ListView listView;private ListViewAdapter adapter;private List<ItemInfo> infoList;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);swipeLayout = (SwipeRefreshLayout) this.findViewById(R.id.swipe_refresh);swipeLayout.setOnRefreshListener(this);// 頂部重新整理的樣式swipeLayout.setColorScheme(android.R.color.holo_red_light, android.R.color.holo_green_light,android.R.color.holo_blue_bright, android.R.color.holo_orange_light);infoList = new ArrayList<ItemInfo>();ItemInfo info = new ItemInfo();info.setName("coin");infoList.add(info);listView = (ListView) this.findViewById(R.id.listview);adapter = new ListViewAdapter(this, infoList);listView.setAdapter(adapter);}public void onRefresh() {new Handler().postDelayed(new Runnable() {public void run() {swipeLayout.setRefreshing(false);ItemInfo info = new ItemInfo();info.setName("coin-refresh");infoList.add(info);adapter.notifyDataSetChanged();}}, 500);}}

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.