布局基础:
1、main.xml代码:
<?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:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:text="red"
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#aa0000"/>
<TextView
android:text="green"
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#00aa00"/>
<TextView
android:text="blue"
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#0000aa"/>
<TextView
android:text="black"
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#000000"/>
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/row1_column1"
android:padding="3dip"/>
<TextView
android:text="@string/row1_column2"
android:gravity="center_vertical"
android:padding="3dip"/>
<TextView
android:text="@string/row1_column3"
android:gravity="right"
android:padding="3dip"/>
</TableRow>
<TableRow>
<TextView
android:text="@string/row2_column1"
android:padding="3dip"/>
<TextView
android:text="@string/row2_column2"
android:gravity="right"
android:padding="3dip"/>
</TableRow>
</TableLayout>
</LinearLayout>
2、LinerText.java代码:
package mras.layout01;
import android.os.Bundle;
import android.app.Activity;
public class LinerText extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
3 、string.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">layout01</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="row1_column1">row1_column1</string>
<string name="row1_column2">row1_column2</string>
<string name="row1_column3">row1_column3</string>
<string name="row2_column1">row2_column1</string>
<string name="row2_column2">row2_column2</string>
</resources>
4、运行效果: