IT/Android

android - LinearLayout, RelativeLayout, TableLayout

노마드오브 2018. 9. 8. 22:05

1. LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="전화번호"
android:textSize="25sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="010-1234-12345" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="입력" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="취소" />
</LinearLayout>


</LinearLayout>


2. RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="전화번호"
android:textSize="25sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="010-1234-4567"
android:layout_toRightOf="@+id/tv1"/>

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv1"
android:layout_alignParentRight="true"
android:text="취소"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/btn1"
android:layout_below="@id/tv1"
android:text="입력" />


</RelativeLayout>


3. TableLayout (TableRow, layout_span, layout_column)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>

<Button
android:layout_width="60dp"
android:text="1" />

<Button
android:layout_width="60dp"
android:layout_span="2"
android:text="2" />

<Button
android:layout_width="60dp"
android:text="3" />
</TableRow>

<TableRow>

<Button
android:layout_width="60dp"
android:layout_column="1"
android:text="4" />

<Button
android:layout_width="60dp"
android:text="5" />

<Button
android:layout_width="60dp"
android:text="6" />
</TableRow>
</TableLayout>


4. TableLayout (stretchColumns)

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,2" >

<TableRow>
<TextView
android:text="111111"
android:background="#ff0000" />
<TextView
android:text="2222"
android:background="#ffff00" />
<TextView
android:text="3333"
android:background="#0000ff" />
</TableRow>

</TableLayout>