In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to achieve the video drop-down and refresh effect done by Android imitating Douyin". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. A brief introduction to SwipeRefreshLayout
Let's take a look at the following official documents, which have been described in great detail.
The official document states
Let me give you a general explanation here:
You can use SwipeRefreshLayout to refresh the page when you slide vertically. It refreshes by setting OnRefreshListener to listen for the sliding of the interface. There are also some ways to set whether the SwipeRefreshLayout can be refreshed. Such as: setRefreshing (true), expand and refresh the animation.
SetRefreshing (false), cancel refreshing the animation. SetEnable (true) drop-down refresh will not be available.
To refresh using this layout, you need to wrap slidable child controls, such as ListView, in this layout, and there can only be one child control.
Summary: drop-down refresh can be achieved using SwipeRefreshLayout, as long as the layout needs to wrap a child control that can slide, then set OnRefreshListener to listen in the code, and finally set the data acquisition during refresh in the monitor. Because it's new, to use it, upgrade the version of support library to 19.1 or newer.
II. Introduction of the main methods of SwipeRefreshLayout
Looking through the official documentation, you can see that there are many methods, and here are only five commonly used methods.
IsRefreshing ()
Determines whether the current state is a refresh state.
SetColorSchemeResources (int... ColorResIds)
Set the color theme of the drop-down progress bar, the parameter is a variable parameter, and it is a resource id, you can set a variety of different colors, displaying one color each turn.
SetOnRefreshListener (SwipeRefreshLayout.OnRefreshListener listener)
To set up listening, you need to override the onRefresh () method, which will be called when you drop down at the top to implement the logic of requesting data, setting the drop-down progress bar to disappear, and so on.
SetProgressBackgroundColorSchemeResource (int colorRes)
Sets the background color of the drop-down progress bar. The default is white.
SetRefreshing (boolean refreshing)
Set the refresh status. True indicates that the refresh is in progress, and false means to cancel the refresh.
Then there will be no more to say, and let's just start:
Effect picture:
Activity_listview layout file
Activity Code (ListViewActivity)
Public class ListViewActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {private SwipeRefreshLayout swipeRefreshLayout; private ListView listView; private List list; private ArrayAdapter adapter; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_list_view); swipeRefreshLayout = (SwipeRefreshLayout) findViewById (R.id.sr1); swipeRefreshLayout.setOnRefreshListener (this); list = new ArrayList (); for (int I = 0polii
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.