Share Coding

Tutorials, Problems, Stuffs …

Android layout_weight create responsive layout

Method 1, Persentage % :

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.7"
    android:orientation="vertical" />

<RelativeLayout
 android:layout_width="0dp"
 android:layout_height="match_parent"
 android:layout_weight="0.3" />

That means the first one get 70% width, and the other get 30% width.

Method 2, ratio:

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical" />

<RelativeLayout
 android:layout_width="0dp"
 android:layout_height="match_parent"
 android:layout_weight="2" />

That means the first one get 1/3 width, and the other get 2/3 width.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: