i'm implementing a activity where the user can see images from different sizes and proportions on a GridView. I don't want to modify this images proportions.
Is it possible with GridViews or my best option is to build a TableLayout and just add each image to a TableRow?
Example: If it loads a 3x4 image, i want it to scale to satify some width and height constraint and them merge the necessary GridView's elements to keep the 3x4 proportion rate.
My objective is to reach something like this: https://www.dropbox.com/s/6jmt2x5ly1k2p92/grid.png
It seems you can as a custom gridview, I haven't tested my own, and too low to comment. So on this link you will find an image on the bottom using a gridview notice that the last item is larger that the rest and the middle left item is also off scaled.
Related
I want to achieve something similar to the attached image
I was thinking of using TableLayout with 2 columns for each row.
There will be padding in order to be apart of each other. Then I will put white background for the cell. Lastly, I'll just add the ImageView and TextView.
The images and text are dynamically generated. I will get the image URL and display them.
So, are there any better or more efficient way for implementing what I want to achieve? TableLayout doesn't seem to be that efficient.
Your diagram looks pretty much like a grid - for which you can use a GridLayout in Android: https://developer.android.com/reference/android/widget/GridLayout.html
A layout that places its children in a rectangular grid.
The grid is composed of a set of infinitely thin lines that separate the viewing area into cells. Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N + 1 grid indices that run from 0 through N inclusive. Regardless of how GridLayout is configured, grid index 0 is fixed to the leading edge of the container and grid index N is fixed to its trailing edge (after padding is taken into account).
Every one of the items in the grid can be a Cardview (https://developer.android.com/training/material/lists-cards.html) - and that way you will also benefit of a consistent look and feel with Android, without much effort.
Take into account that the cards (every item in the grid) will have the same height, tho: How to make a grid layout of CardViews with variable height?.
If the height of the elements will be variable, you should better take a look to the StaggeredGridLayoutManager: https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html
What you have to do is use a RecyclerView with a GridLayoutManager.
For a full working implementation: https://inducesmile.com/android/android-gridlayoutmanager-with-recyclerview-in-material-design/
How to make a offer up kind of grid UI (please look the image 1), it has three same sized columns and height differs according to image size. i have implemented the view with the 3 linear layouts and a scroll view. but it's not very supportive when it comes to memory management. Can i make the view with grid view (since height is different)? or should i use any other method? or is it ok to use scrollview to load about 100 images at a time?
I'd like to have a carousel of images in my app where the single image's width is the same as the screen's width. I tried a few different things, but didn't manage to do this.
The views of the carousel are:
HorizontalScroll --> LinearLayout(horizontal) --> 4*imageView
The problem is that I can't use fill parent as width because it fills the whole LinearLayout. I could probably calculate the right widths programmatically, but I was wondering is there easier way?
Thanks!
I suggest you using GridView with horizontal scrolling. You can achieve almost every functionality and look that you want.
As for example you can use a RecyclerView with GridLayoutManager. Than you can align your Grid in such way, that it will have only one column - thus the image will fit the screens' width, and don't forget to set adjustViewBounds=true
How can I create NxN grid which automatically scale its items to fit entire screen? I need something similar to GridView but without scrolling. I want to have all items visible and fit to screen dimensions.
Well you can get the size that the gridView can fit to, and then set each of the gridView's views size according to it.
This way, there will not have to be a scrolling at all.
So, for example, if you need an NxN grid and you have 100Nx100N pixels available, for each item give 100x100 pixels.
Of course, you might want to add some padding or separators between them, but that's the basic idea.
In order to get the gridView's size (so that you can set the size of each of its views), you can use this sample code I've made, which works on any type of view.
I would like to have a scrollable image gallery that takes up most of the screen. My images are small icons all of the same size. I can have a lot of images. Once the maximum number of images fills the screen horizontally, they should wrap to the next row. If there are more images than will fit in the vertical direction, then it should be possible to scroll vertically to view additional images. I am not sure what layout controls I should be using to accomplish this. An additional feature (be not a must have), is that the images are equally spaced horizontally with the same amount of margin. Any suggestions? Thank you.
Try a GridView.
Use GridView. Perfectly fits your needs.