Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to display image in grid view is scrolling smooth
    text
    copied!<p>First of all, I have already done few things to display image in gridview make smooth when scrolling</p> <p><strong>1. load image from internet on background thread</strong> </p> <pre><code>AsyncTask acyncTask ; HandlerThread handlerThread ; URL imageUrl = new URL(link);&lt;br&gt; HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection(); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setInstanceFollowRedirects(true); InputStream is=conn.getInputStream(); final Bitmap bitmap = BitmapFactory.decodeStream(is); </code></pre> <p><strong>2. make bitmap to sample size to save memory</strong></p> <pre><code>final BitmapFactory.Options option = new BitmapFactory.Options(); option.inJustDecodeBounds = true; BitmapFactory.decodeFile(mFile.getPath(), option); option.inSampleSize = calculateInSampleSize(option , mSize , mSize); option.inJustDecodeBounds = false; option.inPurgeable = true ; option.inDither = false ; option.inScaled = false ; option.inPreferredConfig = Bitmap.Config.ARGB_8888; </code></pre> <p><strong>3. make a cache to save decoded bitmap</strong></p> <pre><code>LruCache lruCache = new LruCache&lt;String , Bitmap&gt;(); </code></pre> <p>in <code>baseadapter getView();</code> I will <code>lruCache.get(key)</code> to take the decoded bitmap </p> <p><strong>4. lazy load when bitmap decoded through handler</strong> </p> <pre><code> Handler handler = new Handler(); handler.post(new Runnable(){ public void run(){ imageView.setimageBitmap(bitmap); } }); </code></pre> <p>Now I am facing a big problem, it still lag a bit when I'm scrolling i have google about something can make the <strong>scrolling better</strong>, don't know really something can improve or the problem is come out from where i have check for each getView() only spend me about <strong>2~6ms</strong> and it will call my code to <strong>async loading the image form worker thread</strong>, so i really don't know why <strong>some apps can loading very smooth</strong>? my case is <strong>when scrolling</strong> the screen will not look like very smooth is it some suggestion can apply?</p> <p>edited : when i am scrolling , the bitmap found in cache and display on the screen , if i fast scroll , it will look like no scroll enough to show the image , it will make my scroll not so smooth , even i have cache down the bitmap in cache </p> <p>here is the adapter code :</p> <pre><code>if (convertView == null) { convertView = layoutInflater.inflate( R.layout.row_display_image_grid, null); viewHolder = new DisplayImageGridViewHolder(); viewHolder.background = (RelativeLayout) convertView .findViewById(R.id.background); viewHolder.image = (ImageView) convertView.findViewById(R.id.image); viewHolder.text = (TextView) convertView.findViewById(R.id.text); viewHolder.position = position; viewHolder.text.setEllipsize(TruncateAt.END); viewHolder.text.setTypeface(typeFace); viewHolder.image.setOnClickListener(this); viewHolder.image.setOnLongClickListener(this); convertView.setTag(viewHolder); } else { viewHolder = (DisplayImageGridViewHolder) convertView.getTag(); } viewHolder.position = position; imageLoader.loadImage(imageLinkList.get(position), viewHolder.image); return convertView; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload