Android location, percentage resizing, and maintaining aspect ratio

I have an image that I created in a larger size than how it will most likely be displayed. Say 200x200. I am testing a device at 800x480 in landscape mode. My goal is to resize this image to 1/4 of the height of the current view, dock in the upper right corner and keep the aspect ratio. This will mean that when viewing at 800x480, my image will be in the upper right corner displayed at 120x120.

I thought that for this I need to use a vertical LinearLayout with weightSum and layout_weights among the elements (using empty elements with layout_weight to fill if necessary) and adjustViewBounds = true in ImageView, but I can not get the effect I'm going to do. Any ideas?

+4
source share
2 answers

You don't even need to worry about weightSum or adjustViewBounds, I don't think so. However, you must be on the right track. Try this (untested) layout and see if it works:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/qtr_img" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:src="@drawable/your_image" android:scaleType="fitCenter" android:layout_alignParentTop="true" android:layout_alignParentRight="true" /> <View android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="3" /> </LinearLayout> 

It simply places a blank snapshot under the image, weighted to make 3/4 of the screen, while ImageView takes up the remaining 1/4. You can also use layout_gravity="right|top" instead of alignParentTop and alignParentRight , but I just prefer it that way. Let me know if this works.

+4
source

and now, as if you, for example, created a form and supported the application on the phone with different resolutions than the emulator (the labels are not aligned). Is it possible to standardize the resolution, use "%" as the unit of measurement instead of px, ...?

0
source

All Articles