How does adapting to different resolutions on Android work?

5

In html for example, objects can (sometimes without any special code) adapt to the size of the window, for example when placing two images of fixed size, if decreasing the window one goes to the bottom line.

But what about an Android App? Are the elements fixed? Does this vary? Do I need to make a different app for each resolution or screen size?

I'm not programming for Android, but I'd like to know what the concept of Apps is.

    
asked by anonymous 18.02.2014 / 15:10

2 answers

5

Answer:

Adapting to different resolutions of the consists of: Values relative to a LinearLayout that would be the Pesos ( android:layout_weight ).

Explanation:

You can assign the property android:layout_weight to its XML elements, which would be like a weight (well say percentage) that is distributed according to the value of this property in all elements that are relative to its LinearLayout , would be a sum of all Weight 's that are declared in Elementos within its LinearLayout which itself has a WeightSum which is a property that says what is the maximum value ( 100% ) their children. By default the value of WeightSum is 1 .

The property itself of WeightSum which is the total weight pattern of LinearLayout would be android:weightSum=x where x would be the weight value (which can be decimal).

The property itself of Layout Weight which is the weight value of a child element of LinearLayout would be android:layout_weight=x where x would be the value of weight (which can be decimal).

Example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:weightSum="1" <!-- aqui está o weightSum -->
    android:orientation="vertical" >
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" <!-- aqui está o weight -->
        android:gravity="top"
        android:hint="@string/message" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/send" />
</LinearLayout>

Result:

Observations:

In%%ofthemessageyoudonothavevaluesinEditTextabsoluteforheight,youonlyhavedpthatwouldbetheweightofthatelement.

Ifyoulookatallthechildelementsofandroid:layout_weight="1" , you will realize that the only element that contains weight would be LinearLayout of the Message, so the sum of all weight's would be EditText . But if there were another element with% weight% also, the total weight would be 1 and would exceed the default limit of 1 of 2 that would be WeightSum .

But if you have LinearLayout of 1 , for example, you could have WeightSum child elements containing 10 each, so each element would have 10 of the total size.

Very important remark:

You may be wondering: Okay, but where do I tell if the weight is for height or for width ??

The answer is: This is strictly tied to android:layout_weight=1 of your 10% that would be this property:

android:orientation="vertical"

From which you can see that it is declared in the% example_configure%, but if it were horizontal the weight's would be applied horizontally only.

Reference

    
18.02.2014 / 15:24
0

Using LinearLayout. A note Of how to use images in android I have already got enough with this now I use this concept, does not put the size you want the component is on the screen, example. places the user field in vertical and horizontal center. and put the distance that he must keep from the right or left corner of the phone. or how it is to size its size according to the right and left margin of the screen that a and according to the size of the screen the image changes and changes the length of the fields maintaining the aesthetics example if I specify the image at size 220x90 it will have this length in all the screen size, so the android comes with 4 folder for these images, just put the images with the same name in each folder and android specifies the best resolution to the screen being opened drawable -hdpi dimension 0.75 drawable-mdpi 1
drawable-xhdpi 1.5 drawable-xxhdpi 2.0

Imagebutton ImageView use the android property: src="@ drawable / image_name"

    
16.03.2014 / 20:34