I have a lot of images in scrollview, I would like to know how to layout them so they would be seen the same on different resolutions. Like if I rotate screen some images would fill the gap.(All activity is only images)
You can use GridLayout.
Check Heterogeneous GridLayout,GridLayout and Row/Column Span Woe.
It might helpful for you.
This issue is behond displaying an image on a gridView but rather about memory limitation and caching(recycling and reusing etc..)
Take a look at this link Displaying Bitmaps Efficiently and try to download a sample on the left called BitmapFun.zip
Related
I have multiple elements in my recyclerview's row -> By multiple I mean multiple in number as well as multiple in type i.e mutliple imageviews, textviews etc.
Following is the gist so that you can see all the elements: https://gist.github.com/Harshhb101/55e25da72e3a474aeeb422d5e231d3e3
The issue is that I need to hide/show these elements based on a parameter which can have upto 10 values. Thus I will have 10 types of rows. Currently I have created only one layout for the row have elements for all types of rows and in some mobiles, the scroll has a lag. Majorly I am getting the lag where the rows have images. I am using Glide to load the images. Following is the gist for the onBindView: https://gist.github.com/Harshhb101/e10feb2cccda9d698ff06487bbb879ef
I did look up on stackoverflow but could not find anything solid but came upon using multiple viewholders. My question is that if I refactor my code, will it make a substantial difference by using multiple viewholders? Or is there something wrong in my approach that could be fixed to get a good scoll.
You need to make your RecyclerView images smaller to save memory and cache them. Read this.
Also if your ViewHolder contains images that has size wrap_content then images are loaded full size what is really bad for performance for example if view size on screen is 48dp x 48dp and picture is full HD, then full HD drawable going to be loaded in to memory what is making your scrolling slow and not smooth.
I suggest using fixed size in ViewHolder or override image size when loading in Glide
Please declare many view type instead of one view type for many kind. It's actually make the code more readability, but not much the reduce the lag because the recycle view/listview is have the reused mechanism.
Recommended to use fixed size in RecycleView.
I saw the Glide used for image loading. So did you config the cache?
I have doubt that you loading the big resolution image
After looking into the code i found couple of improvements.
Don't make God ViewType (One view type for all kind of views). instead create
individual viewtype for each kind of posts. so it'll eliminate the rendering cost of all the views and making them visible and invisble at runtime.
Reference demo of recyclerview with multiple viewtypes
Use some image loading libraries so that you dont have to handle caching images and bitmap related manipulations (Picasso will be good).
Picasso
And lastly avoid doing heavy tasks in onbind() instead prepare your data class specifically for recyclerview (if much caluclation required like heavy string manipulations etc) before setting recyclerview adapter.
on my Activity i've got on each side (on the right/on the left) a constrain Layout (100dp width). Between those gridviews i have a Gridlayout. This grid i fill with the help of an adapter. Now it contains 32*52 squares which contain a black/white image. With buttons placed on the constrain layouts i change the colour of choosen squares. But if i try this on several devices, this way is not realy performant and quite laggy. Is der a better way to do this? How? I found something on Bitmaps and canverals.. would this be better? How should i use this? Can someone recommend a tutorial? Or what other ways of achieving this exists?
Thanks a lot!
As all we know, RecyclerView enhance flexibility and also improve smoothness. So you can use RecyclerView Or RecyclerView with CardView.
And instead of using Bitmaps I would recommend you to use Glide
Library to Show Images
You can use Glide library for display image.So just add it in
build.gradle(Module App)
compile 'com.github.bumptech.glide:glide:3.7.0'
to set Images
Glide.with(context).load(image_path).into(imageView);
Note: image_path can be string, int resource, file or anything else bcoz Glide can load everything
Following are the tutorial links for RecyclerView with cardview:
link1: http://www.androidhive.info/2016/01/android-working-with-recycler-view/
link2: http://www.androidhive.info/2016/05/android-working-with-card-view-and-recycler-view/
I'm a newbie in Android. When I tried to create my dashboard using grid view, in different screens the images became small. I tried various methods to zoom it. But nothing worked for me. Can anyone suggest a solution for me ? I've 8 icons in my dashboard. Also when we put images in drawable folders , what is the size of images in each folder???
You can use auto resized images... GridView with Auto Resized Images on Android may work for you.. This explains a way to create a GridView with two columns and auto resized images inside each view
In my apps i want to display images and text in three ways
ListView
GridView
FullScreen
i have 500+ images and text that i parse using JSON and store into SQLite.
I know how to create ListView & GridView but problem is I don't know how to create the custom layout.
I have image but due to my low reputation i am not able to post image.
I try to explain what i need.
I need custom fullscreen layout that has 2 buttons, one on the left and other on the right and between those 2 buttons I need Imageview that display the fullscreen image.
thanks in advance
Use UniversalImageLoader library, as it has all the modes you need. It also supports caching and lazy load, which you will definitely need on 500 images.
I'm going to draw a grid of 10x10 PNG images. Each image is 32x32 px. All of the images are unique. I'm thinking that the easiest way seems to be to put each image in an ImageView.
If adding all ImageView's to the layout would this give me some kind of performance hit?
Would there be any smarter way to draw these images?
I assume that your grid is a gridview. Than it should have an adapter with your items. There is a getView method in the adapter you need to take look into. You set your images there.
I would look at GridView examples and this example
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html
to take a look how to write efficient adapters.