我正在尝试在Android中实现下拉刷新功能。我知道有SwipeRefreshLayout
,但是在像Drive这样的全新设计的Google应用程序(见附件)中,我注意到在拉动时出现了一个新的刷新图标。我尝试在网上查找,但徒劳无功。
编辑:有些人指出这是如何实现下拉刷新的重复问题。这不是同一个问题。如果您仔细阅读问题,就会发现这一点。
我正在尝试在Android中实现下拉刷新功能。我知道有SwipeRefreshLayout
,但是在像Drive这样的全新设计的Google应用程序(见附件)中,我注意到在拉动时出现了一个新的刷新图标。我尝试在网上查找,但徒劳无功。
编辑:有些人指出这是如何实现下拉刷新的重复问题。这不是同一个问题。如果您仔细阅读问题,就会发现这一点。
这是 SwipeRefreshLayout
。支持库的版本21中包含了它,替代了旧样式。
详细指南可以在此处找到:http://antonioleiva.com/swiperefreshlayout/
另外,对于ListView,我建议阅读一下评论中的canChildScrollUp();)
我最喜欢的是这个指南,它非常易懂:https://www.bignerdranch.com/blog/implementing-swipe-to-refresh/
Add the following to gradle:
compile 'com.android.support:support-v4:22.2.0'
Add the swipe to refresh to your layout - put in listview or recyclerview in the middle of the swiperefreshlayout:
<ListView
android:id="@+id/activity_main_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
Add in your code for the mainactivity:
public class MainActivity extends Activity {
ListView mListView;
SwipeRefreshLayout mSwipeRefreshLayout;
Adapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acivity_main);
SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
mListView = findViewById(R.id.activity_main_list_view);
mListView.setAdapter(new ArrayAdapter<String>(){
String[] fakeTweets = getResources().getStringArray(R.array.fake_tweets);
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fakeTweets)
listView.setAdapter(mAdapter);
});
}
}
Don't forget to call mSwipeRefreshLayout.setRefreshing(false); once your refreshing ends.
嗨,如果你想开发这种布局,请访问以下链接。我曾经使用过它,效果非常棒。