[Demo with instance] Google pull-down refresh component --- SwipeRefreshLayout

Source: Internet
Author: User

Link: https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html#inhfields


Scene: the day before yesterday, Xiaohai told me that Google, apart from its own refresh control, is indeed SwipeRefreshLayout.

SwipeRefreshLayout literally refers to the pull-down refresh layout, inherited from ViewGroup, under the support v4 compatibility package (android. support. v4.widget. swipeRefreshLayout), but you must upgrade your support library version to 19.1. When it comes to pull-down refresh, everyone must be familiar with ActionBarPullToRefresh. Now google has launched a more official pull-down refresh component, which is undoubtedly a good news for developers. You can use this component to easily refresh Google Now. For details, see:


Xml layout File

This layout shoshould be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child.

Add SwipeRefreshLayout to the outermost layer of the control to be refreshed, and then its child is first a scrollable view, such as ScrollView or ListView.
<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:ignore="MergeRootFrame" >    <android.support.v4.widget.SwipeRefreshLayout        android:id="@+id/swipe_container"        android:layout_width="match_parent"        android:layout_height="match_parent" >        <ListView            android:id="@+id/list"            android:layout_width="match_parent"            android:layout_height="match_parent" >        </ListView>    </android.support.v4.widget.SwipeRefreshLayout></FrameLayout>

Activity Code:

Package com. jabony. swiperefreshlayou; import java. util. arrayList; import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. support. v4.widget. swipeRefreshLayout; import android. widget. listView; import com. jabony. swiperefreshlayout. r; public class SwipRefreshLayoutActivity extends Activity implementsSwipeRefreshLayout. onRefreshListener {private synchronized swipeLayout; private ListView listView; private ListViewAdapter adapter; private ArrayList <SoftwareClassificationInfo> list; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. swipe_refresh_layout); swipeLayout = (SwipeRefreshLayout) findViewById (R. id. swipe_container); swipeLayout. setOnRefreshListener (this); // The loaded color is played cyclically. As long as the refresh is not completed, the loop continues. color1> color2> color3> color4swipeLayout. setColorScheme (android. r. color. white, android. r. color. holo_green_light, android. r. color. holo_orange_light, android. r. color. holo_red_light); list = new ArrayList <SoftwareClassificationInfo> (); list. add (new SoftwareClassificationInfo (1, "asdas"); listView = (ListView) findViewById (R. id. list); adapter = new ListViewAdapter (this, list); listView. setAdapter (adapter);} public void onRefresh () {new Handler (). postDelayed (new Runnable () {public void run () {swipeLayout. setRefreshing (false); list. add (new SoftwareClassificationInfo (2, "ass"); adapter. notifyDataSetChanged () ;}, 3000 );}}

Main Methods:

  • SetOnRefreshListener (OnRefreshListener): adds a Listener for the layout.
  • SetRefreshing (boolean): display or hide the refresh progress bar
  • IsRefreshing (): checks whether a refresh status is in progress.
  • SetColorScheme (): Set the color topic of the progress bar. You can set up to four

Summary: Every time a friend tells me something new, he is very happy because it is another opportunity for progress. I hope you can make progress together with me. Google is constantly improving its own SDK, so what are the reasons for us not to follow up with the times to learn new designs? It is clear that we wish you a pleasant holiday and it is best not to work overtime!

Attachment: attached later (no points)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.