In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people don't understand the knowledge points of this article "How to use ListView to achieve smooth scrolling in Android", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "How to use ListView to achieve smooth scrolling in Android".
Using background threads
Using background threads ("worker threads") removes the stress from the main thread so that you can concentrate on drawing the UI. In many cases, taking advantage of AsyncTask provides an easy way to perform your work outside of the main thread. AsyncTask automatically queues all_execute()) requests and executes them sequentially. This behavior is global to a particular process, which means you don't have to worry about creating your own thread pool.
In the simple code shown below, AsyncTask is used to load the image in a background thread and then applied to the UI once it is complete. You can also display a progress bar instead of loading images.
//Load slow images in background thread with AsyncTask new AsyncTask() { private ViewHolder v; @Override protected Bitmap doInBackground(ViewHolder... params) { v = params[0]; return mFakeImageLoader.getImage(); } @Override protected void onPostExecute(Bitmap result) { super.onPostExecute(result); if (v.position == position) { //Hide progress bar, set and display image if item has not been recycled v.progress.setVisibility(View.GONE); v.icon.setVisibility(View.VISIBLE); v.icon.setImageBitmap(result); } }}.execute(holder);
As of Android 3.0 (API Level 11), a new feature is available in AsyncTask that you can turn on to
Crossover threads between multiprocessor cores. Instead of calling the ** execute()** method, you can execute multiple requests simultaneously using the **executeOnExecutor()** method, depending on the number of cores available.
Saving View Objects in View Holder
Your code may frequently call findViewById() when scrolling ListView, which can slow down the effect. Even if the Adapter returns a view that is already exposed for recycling, you still need to find these elements and update them. One way to cycle findViewById() is to use the "view holder" design pattern.
A findViewById() object stores the markup fields of each component view within the layout, and you can access them immediately without having to query them repeatedly. First, you need to create a class to hold concrete views. For example:
static class ViewHolder { TextView text; TextView timestamp; ImageView icon; ProgressBar progress; int position;}
Then fill in findViewById() and save it in the layout.
ViewHolder holder = new ViewHolder(); holder.icon =(ImageView) convertView.findViewById (R.id.listitem_image); holder.text =(TextView) convertView.findViewById (R.id.listitem_text); holder.timestamp =(TextView) convertView.findViewById (R.id.listitem_timestamp); holder.progress =(ProgressBar) convertView.findViewById (R.id.progress_spinner); convertView.setTag(holder); The above is about "Android how to use ListView to achieve smooth scrolling" The content of this article, I believe everyone has a certain understanding, I hope the content shared by Xiaobian is helpful to everyone, if you want to know more related knowledge content, please pay attention to the industry information channel.
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.