Rea*_*lar 33 android android-listview pull-to-refresh
谷歌发布了新的Gmail应用程序,以另一种方式处理下拉刷新.
而不是显示已下拉的已启动隐藏行.Gmail会在操作栏上方显示动画消息.
该消息包括动画水平线.
这是Android SDK的标准功能吗?我在动作栏API中找不到任何可以执行此操作的内容.
Boo*_*ger 48
Google已直接在SDK中发布了对此的支持.我不确定你需要支持哪个版本(这可能是一个问题).
在这里查看官方SDK功能信息:http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
如果你能够使用SDK,你会更好,甚至克里斯巴恩斯写了一篇文章,建议相同.
laa*_*lto 22
Chris Banes在GitHub上的ActionBar-PullToRefresh库可能提供最接近GMail应用程序的pull-to-refresh功能.
另见:JuhaniLehtimäki对GMail pull-to-refresh的分析.
小智 10
试试这个......这对我有用.
RES /布局/ activity_main.xml中
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.swipetorefresh.MainActivity"
tools:ignore="MergeRootFrame" />
Run Code Online (Sandbox Code Playgroud)
RES /布局/ fragment_main.xml
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MergeRootFrame" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
public static class PlaceholderFragment extends ListFragment implements OnRefreshListener {
private SwipeRefreshLayout mSwipeRefreshLayout;
private static final int LIST_ITEM_COUNT = 5;
private int mOffset = 0;
private ArrayAdapter<String> mListAdapter;
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
// Configure the swipe refresh layout
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.container);
mSwipeRefreshLayout.setOnRefreshListener(this);
mSwipeRefreshLayout.setColorScheme(
R.color.swipe_color_1, R.color.swipe_color_2,
R.color.swipe_color_3, R.color.swipe_color_4);
// Put the first batch of countries in the list
mListAdapter = new ArrayAdapter<String>(
getActivity(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
getCountries(mOffset));
setListAdapter(mListAdapter);
return rootView;
}
private List<String> getCountries(int offset) {
ArrayList<String> countriesList = new ArrayList<String>();
for(int i=0; i<LIST_ITEM_COUNT;i++){
countriesList.add(COUNTRIES[offset+i]);
}
mOffset = offset + LIST_ITEM_COUNT;
return countriesList;
}
@Override
public void onRefresh() {
// Start showing the refresh animation
mSwipeRefreshLayout.setRefreshing(true);
// Simulate a long running activity
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
updateCountries();
}
}, 5000);
}
private void updateCountries() {
// Add the next batch of countries to the list
mListAdapter.addAll(getCountries(mOffset));
// Signify that we are done refreshing
mSwipeRefreshLayout.setRefreshing(false);
}
private static final String[] COUNTRIES = {"Afghanistan",
"Albania", "Algeria", "American Samoa", "Andorra", "Angola",
"Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
"Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
"Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus",
"Belgium", "Belize", "Benin", "Bermuda", "Bhutan",
"Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil",
"Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi",
"Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands",
"Central African Republic", "Chad", "Chile", "China",
"Christmas Island", "Cocos (Keeling) Islands", "Colombia",
"Comoros", "Democratic Republic of the Congo (Kinshasa)",
"Congo, Republic of(Brazzaville)", "Cook Islands", "Costa Rica",
"Ivory Coast", "Croatia", "Cuba", "Cyprus", "Czech Republic",
"Denmark", "Djibouti", "Dominica", "Dominican Republic",
"East Timor (Timor-Leste)", "Ecuador", "Egypt",
"El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia"};
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
43375 次 |
最近记录: |