您的位置:首页 > 编程语言 > Go语言

google官方上拉刷新

2016-04-17 22:42 337 查看
另外一种写法,但是这种写法的背景是黑色,现在还不能调成白色。。。

package com.jredu;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

private SwipeRefreshLayout swipeRefreshLayout;
private ListView myList;
private List<String> data;
private ArrayAdapter<String> adapter;

@SuppressLint("ResourceAsColor")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
myList = (ListView) findViewById(R.id.mylist);
data = new ArrayList<String>();

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
myList.setAdapter(adapter);

swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);
// 设置下拉圆圈上的颜色
swipeRefreshLayout.setColorSchemeResources(R.color.swipe_color_1, R.color.swipe_color_2, R.color.swipe_color_3,
R.color.swipe_color_4);
// 设置手指在屏幕下拉多少距离会触发下拉刷新
// mSwipeLayout.setDistanceToTriggerSync(400);
// 设置圆圈的大小
swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);
// 设定下拉圆圈的背景
swipeRefreshLayout.setProgressBackgroundColor(R.color.swipe_background_color);
// swipeRefreshLayout.setPadding(20, 20, 20, 20);
// swipeRefreshLayout.setProgressViewOffset(true, 100, 200);
// swipeRefreshLayout.setDistanceToTriggerSync(50);
//刷新指示器静止位置总是位于靠近清爽内容的顶部。
swipeRefreshLayout.setProgressViewEndTarget(true, 100);
swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
new Thread(new Runnable() {
@Override
public void run() {
data.clear();
for (int i = 0; i < 20; i++) {
data.add("SwipeRefreshLayout下拉刷新" + i);
}

mHandler.sendEmptyMessage(1);
}
}).start();
}
});
}

private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:

swipeRefreshLayout.setRefreshing(false);
adapter.notifyDataSetChanged();
// swipeRefreshLayout.setEnabled(false);
break;
default:
break;
}
}

};
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jredu"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />

<application
android:theme="@android:style/Theme.NoTitleBar"
android:allowBackup="true"
android:icon="@drawable/ic_launcher" >
<activity android:name="com.jredu.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

参考链接 : zhanghongyang http://blog.csdn.net/lmj623565791/article/details/38238749/ 

他的代码中已经写好了上拉刷新和下拉加载,注意是两个工程(其中一个是工具类)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  google上拉刷新