1

Hey there I am new in Android Studio and I have one question which makes me mad all the time.. whenever I use Single Layout for example Relative layout. then it works fine but sometime the components(contents) does not show properly while display.

Do we need to Make different layouts for every single components ? Please Help me out . Thanks in Advance.

Zain1122
  • 45
  • 1
  • 7

2 Answers2

0

No basically layouts are for our convenience, and every layout has its own unique use.

like...

  1. linear layout for linear structure with weight(optional).
  2. relative layout for set component free and its position relative to each other as well as to parent.
  3. frame layout for use component free and position with gravity.
  4. grid layout for set component in grid structure,

for some complex design you may use nested structure of layouts.

RBK
  • 2,481
  • 2
  • 30
  • 52
0

All Layouts have Unique functionalities. Depends on the style, which layout is suitable for that.

Linear and Relative are most common used. The difference is that... In Relative Layout, all the widgets are controlled by ids. example...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
    android:text="Hello"
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<Button
    android:layout_below="@+id/text1"
    android:text="Done"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</RelativeLayout>

In LinearLayout. you have weights.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="horizontal">

<TextView
    android:layout_weight="1"
    android:text="Hello"
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<Button
    android:layout_weight="1"
    android:layout_below="@+id/text1"
    android:text="Done"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
 </LinearLayout>

In Grid Layout have rows and Columns to adjust your layout.

Note.... One Activity have Multiple Layouts...... :) Cheeers .... !!!!

Muhammad Fahad
  • 101
  • 2
  • 10
  • Thank you so much fahad and i hope we both need to learn lot of things in the world of android :) best wishes – Zain1122 Nov 04 '15 at 13:26