How to maintain aspect ratio on an Android Gallery - android

I have an Android Gallery setup on a layout with both the width and height set to Fill_Parent. This works great for smaller screens, but as the display size grows into the tablet sizes, the Gallery stretches to a layout that is taller than it is wide. At this point, there are no more side images on it - that is, just the main selected image is visible. I want to have at least a small amount of the side images visible so the user knows the view is scrollable.
Does anybody know how I can do this?
Is it possible to maintain an aspect ratio while still using fill_parent? Is it possible to set the Gallery view to show a certain amount of the side images? etc?
Thanks!

The Gallery class is pretty limited and personally I tend not to use it. Have you considered using a ViewPager instead?

AFAIK, If you are using
android.widget.Gallery
then the implement a custom adapter to the view, and set a layout wrapped to each items inside the gallery view. If you still don't understand what I just said, I would try to generate some reference code.

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.

How to create a group of image views

I wanna create a group of image views as below, and I can update background images. I wonder whether I should create 7 image-views on the layout or I should create each image view programmatically, like creating a list? Thanks.
I'd say it depends on the data. Will you always have 7 or could you have less, or maybe even more? Do you need to display 7 or can it depend on the screen width? Do they need to be a certain size or can they shrink to fit on narrower screens?
If it's guaranteed to be always exactly 7 and you're happy for them to scale to fit the screen then I'd use an XML layout but if it can vary then I'd render it programatically using a horizontal RecyclerView to show as many as possible on the screen and allow the user to scroll through them.

how to set best size of Imageview for the different sized images in Listview

I am developing an android app. What I am trying to do is a listview with custom view having some text and an images. The images I am downloading from internet have different size. And I want to resize them without changing their appearance. If I set ImageView height and weight in xml file, my app will have same appearance on different screen size devices. If I set ImageView layout size to wrap content, images looks terrible in app because they each of them have different size. An idea or tutorial would be nice. Thanks.
I think what you would want to do is resize the images in something like gimp or photoshop, and save multiple copies of the images at different sizes.
You'll want to look up this tutorial.
The scaleType attribute of ImageView is very useful in fixing resizing issues on different screen sizes. This site has sample images of all scaleTypes.
One solution is to use a sufficiently large image, specify match_parent as the layout_width of the ImageView, and use an exact layout_height in dp. If scaleType is centerCrop, the image's dimension is maintained [although only a part of the image may be shown, depending on the screen size].

Button height dynamic

I want to create my button height using drawable xml file and it should also resize dynamically with my layout, so that it can support any Android device.
Currently I am using RelativeLayout with match_parent height. I want to put a set of 3X4 buttons in this layout and should automatically resize with the device height.
I am not able to resize it properly when I use dp values. If I resize the button for large res device, it is not working fine for 240X320 res device.
Yes, you should be able to do what you want with the Android layout classes. You aren't completely clear, but it sounds like GridLayout is what you want.
The default Android UI element should deal well with being sized dynamically; if you have a custom drawable asset, you'll want to make an appropriate 9-patch image at each of the common display densities (so that it not only resizes correctly, but looks good on a range of devices).
I have recently been thinking about this very topic, and I think I can help you. If I understand you correctly, you would like to have your application dynamically resize your buttons depending on the screen size. In order to do that you can use binding and a converter. If you bind your button's height (and width if you prefer) to the page's height (and width) you can use a converter to convert the value to a percentage of the screen size. If you like, I can provide you with some sample code.
You can get the size of the display Display display = getWindowManager().getDefaultDisplay(); and set the sizes dinamically.
Or, you can make various sizes of your images.

How to design ImageViews that stretch according to the screen-size

I have a requirement where few of my image views form border areas of an application, and the application will be running on many screen sizes.
I'll be creating a uniform image for the smallest size possible, which can be repeated as many times as needed, and still presents the same image.
I want the image view to replicate the image contained whenever it is increased.
Is anything like this possible?
I tried 9-patch images, but I couldn't find nice articles on it which could explain how to create useful images with it which could suit my need.
I think you have to write a custom view to do this. Overide onDraw method in it to copy your bitmap as many times as needed.
Get the width and height of the device dynamically and set the imageview width and height in program.

Categories

Resources