I am trying to create intro tour for the app with 4 image using viewpager. Its taking very much time to slide from previous to next image.
I am getting following log in logcat while sliding
I/Choreographer: Skipped 100 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 94 frames! The application may be doing too much work on its main thread.
I tried following methods:
1 setImageResource() does Bitmap reading and decoding on the UI thread, which can cause a latency hiccup. If that's a concern, consider using 2.setImageDrawable(android.graphics.drawable.Drawable) or 3.setImageBitmap(android.graphics.Bitmap) and BitmapFactory instead. Size and resolution of your images can also be a cause of slow scrolling, try creating thumbnails images of your large images and use.(I reduce images size from 100kb to 30-50kb in drawable)
Also tried stack overflow answers below:
Memory leak with images in viewpager
Still images taking much time from previous to next images in view pager . I tested it on different device. On moto x play its slowest and other devices like samsung, moto E, Lenovo are little faster but still not upto mark.
I have 4 images in drawable folder and using code below I am trying to slide the images.
@Override
public int getCount() {
return mResources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == (object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View itemView = LayoutInflater.from(mContext).inflate(R.layout.pager_item, container, false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.img_pager_item);
imageView.setImageDrawable(mResources[position]);
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout) object);
}
Thanks in advance !
Try Putting your Images in particular Drawable folder to View in different densities! so you don't have any rendering problems
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps, shrink or enlarge. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With