您好,登錄后才能下訂單哦!
API doc:http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
Google在support v4 19.1版本推出了一個下拉刷新組件SwipeRefreshLayout,使用起來方便,效果優(yōu)美,但要注意的是其布局中只能有一個直接子布局。使用步驟如下:
1.在xml中,加載android.support.v4.widget.SwipeRefreshLayout
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layout_containter" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent"></ListView> </android.support.v4.widget.SwipeRefreshLayout>
2.使用
package com.example.testswiperefreshlayout; import android.os.Bundle; import android.os.Handler; import android.annotation.SuppressLint; import android.app.Activity; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; public class MainActivity extends Activity implements OnRefreshListener { private SwipeRefreshLayout mSwipeRefreshLayout; private ListView mList; @SuppressLint("InlinedApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mList = (ListView) findViewById(R.id.list); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.layout_containter); mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); mSwipeRefreshLayout.setOnRefreshListener(this); } @Override public void onRefresh() { new Handler().postDelayed(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(false); mList.setAdapter(new MyAdapter()); } }, 5000); } class MyAdapter extends BaseAdapter { @Override public int getCount() { return 10; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { View inflate = null; TextView tvItem = null; if (convertView == null) { inflate = getLayoutInflater().inflate(R.layout.listview_item, null); tvItem = (TextView) inflate.findViewById(R.id.tv_item); inflate.setTag(tvItem); } else { inflate = convertView; tvItem = (TextView) inflate.getTag(); } tvItem.setText("下拉刷新item"+position); return inflate; } } }
×××地址:http://download.csdn.net/detail/dennisruan/9433027
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。