Maintaining Image Proportions in GridView Application Widgets

I am working on an app with several app widgets and some of them use GridView

to display their content. The content is a bunch of movie cover images and I would like to keep the original aspect ratio of the images.

Alternatively, I am looking for a way to declare the aspect ratio for the images. It is important that the images still fit the width GridView

when the user resizes the application widget.

Since it is not possible to use subclasses ImageView

when working with RemoteView

s, this is out of the question. I am currently using ScaleType.CENTER_CROP

on ImageView

as well as a specific height and width, but as you can imagine, this is not ideal.

Any suggestions?

+3


source to share


5 answers


Have you tried this method on your ImageView?

    imageView.setAdjustViewBounds(true);

      



I found it thanks to this one.

+5


source


Try setting the GridView's columnWidth as the image width, numColumns as "auto_fit" and stretchMode as "spacingWidth":



<GridView
        android:id="@+id/gridView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnWidth="50dp"
        android:numColumns="auto_fit"
        android:stretchMode="spacingWidth" />

      

+1


source


Create a subclass of the remote view where when setting up the bitmap use something like:

fooobar.com/questions/47750 / ...

or override onMeasure in this situation:

fooobar.com/questions/47758 / ...

+1


source


ImageView is slightly different from TextView. ImageView has a "src" which defines the foreground image in the widgets. If you set a background in the image, it will appear behind the foreground. Both of these images are manipulated differently by android:stretchMode

other android options.

I suggest you change all of yours android:src

to android:background

and vice versa to get a sample of what you think will work for you. After you get a few images the way you want to see them, then manipulate the images with GIMP, Photoshop, so that their size is the same as what you think you want. The images themselves need to be good for these parameters to work well with it. Image size, density and XY ratio.

+1


source


See RelativeLayout + ShapeDrawable method used for another aspect of app aspect ratio: How to fill ImageView in Appwidget while maintaining aspect ratio?

It works within the limitations of AppWidget and should be applicable to this problem.

0


source







All Articles