Android layout scaling

If you set the target version of the SDK in the Android manifest file to β€œ3,” then your layout on large-screen devices will be just an extended version of what it is on small-screen devices. After you set the target SDK to a higher SDK, you can create separate layouts for each screen density, which provides a much better user interface.

However, my layout mainly consists of images that have a fairly high resolution, which they display on all screen sizes, even if they are enlarged, because they are large enough, no need to stretch. Now it would be much easier for me to create a screen layout and enlarge it, because it will look beautiful on large screens. Is there any way to get this effect without returning to API level 3?

+4
source share
5 answers

You can use the weight parameter.
"weight" is a term that is used to determine which part of the screen should occupy a particular look if any room is left after drawing it.

Just make a LinearLayout and put in it two TextViews as such:

 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="small" android:layout_weight="0.2" android:background="#123" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.8" android:text="huge" android:background="#456" /> </LinearLayout> 

You will notice how species occupy space accordingly. You can create any layout you want for a smaller screen and specify a weight attribute, and each thing will be perfectly adjusted.

+6
source

Just do not specify the layout for large screens. By default, it uses the same for all screens, unless a more specific layout is available. If you use match_parent for width and height, and images for scaleType="fitCenter" or "centerCrop" are similar things, it should fill in any size of the screen it is running on.

+4
source

Remember to make the app suitable for tablets. You must add

 <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" /> 

in the application manifest.

+2
source

Hm. I thought Android already did this until you use something like AbsoluteLayout. There are several tricks that can help with the transition. Not quite sure what the question is asking, but I'll give him a chance. Does API level 3 have aspect ratio or something else?

I found that most of the UI ugliness going from phone to tablet deals with width. There you can set the logic to fix the width at a certain res. Otherwise, the layout looks and acts normally. There are other tricks, such as the presence of assets using different dens.xml and the presence of different sets of dia.xml for different screen sizes and densities.

You do not need to have every dimension in every version. You just need to have a basic version of each set value, and you can set a different dimension in other files.

0
source

The only way to resize images using different screen sizes is to use nine patches. Here are more resources on this subject: http://developer.android.com/tools/help/draw9patch.html

I believe that this is the only thing you can do is use the relative width / height (weight) and images formatted in nineties in the layout.

0
source

Source: https://habr.com/ru/post/1442345/


All Articles