Setting image width in carousel in Android Studio - android

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

Related

ImageViewPager Wrapping height dynamically according to the child image (view)

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.

Android special layout

I need to create a layout in Android like the image below:
The red rectange is the viewport. it should be possible to zoom in and pan until the borders of the image that contains the 4 imageviews.
I've tried putting the images in a gridview, that didn't really work
After that i tried putting them in a tablelayout, but the images have to keep aspect ratio.
so each row in the tablelayout had the correct width but the height was only half the rowview.
So when i pan it's possible to see the white edges from the rowview that was not filled completely
What would be the best way to achieve this layout?

How to create NxN non scrollable grid?

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.

How to merge elements of a GridView

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.

How to set row height of GridView fit to Screen in Android

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

Categories

Resources