ImageView causes lag - java

I have a ImageView in my app. Everything was fine with the first version of my image:
Version 1 of image. But when I updated the image: Version 2 of image, my GUI starts to lag!
For example the animation of a button-click is just displayed with 3~4 frames!
But for me it makes no sense. Both images are png and have a transparent background. The image that causes the lags is even smaller than the old one.

Move the image to a drawable-nodpi folder and see if it makes a difference. Ideally you should put different size images for different resolutions in different folders so that scaling does not cause lags.

You cannot use larger image like that. Because of size the phone lag so much.
In my experience i use the following rules:
if image bigger than 1080x1920 (today many phone has similar resolution) I convert image into a JPG image
if smaller, I keep going to use PNG

Related

Universal Image Loader is too slow

I am trying to show images from URL.
In my code I used, imageLoader.get function but loading images are too slow.
imageLoader.get(c.getImgUrl(), ImageLoader.getImageListener(holder.mImage, R.drawable.img_loading, R.drawable.img_loading)); //450x200 px images.
Then I tried to compress but the problem is still alive.
imageLoader.get(c.getImgUrl(), ImageLoader.getImageListener(holder.mImage, R.drawable.img_loading, R.drawable.img_loading),225,100);
Besides, images are not shown in correct order firstly. When I scroll down(I show 20 images at the same time with recycler view), at first glance it shows images in wrong order. After 3-4 seconds, it shows correctly. Images changes automatically if I scroll down.
As a result, How can I solve my problem? How to speed up? How to show in correct order at first glance?
You can use Glide for that which is far better in memory consumption than compared to other libraries. Also, it provides the diskCacheStrategy, imageResizing, centerCropping, placeholder for the image if not available and can set error image or message if error loading image occurs.
Below is the latest dependency you can include in you app level build.gradle file:
implementation 'com.github.bumptech.glide:glide:4.7.1'
you can use Picasso image library easy to use
http://square.github.io/picasso/

Animated Splash screen in Netbeans Java

I am trying to make animated Gif Splash screen in java netbeans but it doesn't works.. so I use jpg or PNG files it works .. I want to use gif animated file in splash screen I am using -splash:src/Images/sspp.PNG in VM options.. please tell some solutions so I am able to use animated splash screen.
I think you'll find that the problem comes down to two things...
1.Using the command line parameter (-splash), Java expects the image to be a file on the file system, whereas the manifest file expects it to be an embedded resource.
2.Java doesn't seem capable of playing optimised gifs, that is gifs whose frames represent the difference between the last and current frame, instead of a complete image (as far as the splash screen goes).
I tried using
and
The first image failed, but the second worked, the difference, as near as I can tell, is the first is optimized and the second is not...

Best way to store and display images in Android

I am developing an application which can edit images. At the start of my program the user sees a list of folders that contain images. Instead of showing default folder icon i am showing an image from folder. I have database where i store path to images and information about which image is displaying in the list near the folder name. Every time when my application starts it takes a lot of time to load a scaled down image into memory and then display it, especially when there are a lot of folders with images and for each i need to load its icon. I have read this article http://developer.android.com/training/displaying-bitmaps/index.html and every time when my app starts i am scaling down every image.
May be the best way in this situation is to resize (not scale down) every image and then store it in the database? But i have read that this is not good.
So i want to ask an advice of how to do in this case? And i also need an advice of how to optimize displaying images in the Android Galllery widget to make it scrolling more faster. Thank you very much!
1 Never store images in database. It is inefficient and slow.
2 There are several image loading libraries that solve the same problem. My favorites are Picasso and Universal Image Loader

Running Android app with web view on various devices with various physical sizes and resolutions

I've got Android application running in landscape mode on 10" tablet with 1280x800 px resolution. App contains web view including picture with 1280x720 px size, so it's kind of full screen web view.
If I run the very same application on HTC One X smartphone, which is 4.7", 720 x 1280 px, also in landscape mode, web view seems to display only part of the picture, much less as I would expect. It even looks like physical 1/4 of the original, top left quarter.
Does anybody have any experience of running same app on similar or even different resolutions with completely different physical screen sizes?
Any recommendations?
For instance, I would like to run this app also on 7" tablets, where the resolution is only 1024x600 px. Can I still do that without need of changing picture size?
That is just the behavior of a web view/web page in general. Unless you tell it to with JavaScript or css, it wont care how big your screen is and will display all the content at the exact pixel size specified. You can more than likely dynamically re-size the image with JavaScript or css.
This may be what you are looking for: How can I resize an image dynamically with CSS as the browser width/height changes?
According to this thread:
Android Webview initial zoom out
This is the right answer:
webview.getSettings().setLoadWithOverviewMode(true);
This will cause the webview to be zoomed out initially.
webview.getSettings().setUseWideViewPort(true);
The Webview will have a normal viewport (like desktop browser),
You can create separate stylesheets for each density.
http://developer.android.com/guide/webapps/targeting.html#DensityCSS
just to conclude this, all changes had to be done on portal side in html, js and css in order to display it correctly on various tablets.
Playing with settings of WebView element didn't help in this case.

Screen optimization for tablets

I have optimized my app for just about all Android phones. The way my app is set up, I have a 16dp padding on the left and right side of it and a 65dp padding on top and bottom (see screenshot below). On a phone it looks beautiful.
But on a tablet, it looks terrible. 65dp on a phone is a whole lot different that 65dp on a tablet. On a tablet, the black border around the question runs off the side of the scroll background and stuff is on the roll at the top and bottom of the scroll background.
What are my options to fix this? Is there a percentage/weight option for padding? I think that would solve it completely but there is nothing like that that I know of.
You can create multiple resource files tailored for different display sizes. Android will automatically choose the correct resource file for you. Using this technique, you can specify padding values for any screen size, or even completely unique layouts, to be automatically selected for you by Android.
Please refer to Designing for Multiple Screens.
Using multiple dimension resource files would make the task of changing the padding based on screen size very simple. See More Resource Types.

Categories

Resources