I want to stretch the row of a GridView to match the height of the screen in Android.
How do I do this?
You are in control over your row heights, by virtue of what you put in
them. Since your cells appear to have more than one widget, they are
presumably wrapped in a LinearLayout or something. Set your
LinearLayouts to be some specific height, and the rows will all be
that height.
Personally, I think you should be resizing your images if you are
going to have text above and below each image on a per-cell basis.
With the Reference commonsware link
Related
I am trying to move my app from using GridView to using RecyclerView with GridLayoutManager. I am new to RecylcerViews, but have successfully converted my ListViews, now working on my GridView. A couple things I am unsure about:
My current GridView has a certain number of columns, determined at runtime, with each grid column the same, hard-coded width. It is scrollable both horizontally and vertically (I wrap my Gridview in a HorizontalScrollView). So I basically need to have a view with a set number of columns that are a set width, irrespective of screen width.
I have been having problems finding a method to set the column(span) width for GridLayoutManager, so I assume that is not how GridLayoutManager. It almost sounds like it is built to always fit all columns on the screen, rather than letting them spill off the screen? What is the best way to tell GridLayoutManager that I want, for example, 6 columns that are each 150 units wide (either dp or pixels)?
For scrolling in both directions, it sounds like I can use my current approach and just wrap my RecyclerView in a HorizontalScrollView, is that correct?
Make the width of the RecyclerView wrap_content and set the number of spans you want. (Make sure parents of the RecyclerView are also wrap_content.) When you create the item views in the RecyclerView's onCreateViewHolder() make sure that it is the width that you want. The RecyclerView will grow to the width of the view holder layout times the number of spans.
All you need to do now is to wrap everything in a HorizontalScrollView.
Is there a way to dynamically set the ViewPager to wrap the child image just nice without leaving any space in between the height of the view pager and the top and bottom of the image?
I tried using the solution of https://gist.github.com/egslava/589b82a6add9c816a007
But the solution in the link only wraps all the images according to the height of the highest child view. Which makes every other smaller lower images look even flatter.
Is there a way to wrap the images according to each height of the child images? I don't mind the width being cropped off, I'm just more worried about the height. Some of my images fits perfectly without any loose spaces but there are a few which seems too flat in the view pager.
Hope to see your answers soon. Thanks for reading.
If it's white space you want to avoid why not try setting background to transparent.
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'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.