In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.