1. 程式人生 > >常用UI布局

常用UI布局

wrap eat ble button .com ack height 界面 align

技術分享圖片

技術分享圖片

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="280dp" android:layout_height="280dp" android:background="#33FFFF" android:layout_gravity="center"/> <TextView android:layout_width="220dp" android:layout_height="220dp" android:background="#33CCFF" android:layout_gravity="center"/> <TextView android:layout_width="160dp" android:layout_height="160dp" android:background="#3399FF" android:layout_gravity="center"/> <TextView android:layout_width="80dp" android:layout_height="80dp" android:background="#3366FF" android:layout_gravity="center"/> <TextView android:layout_width="20dp" android:layout_height="20dp" android:background="#3300FF" android:layout_gravity="center"/>

</FrameLayout>

<EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp" android:paddingLeft="20dp" android:text="Message" >

</EditText>

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/editText1" android:layout_below="@+id/editText1" android:layout_marginTop="20dp" android:text="OK" />

<?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" >

<EditText android:id="@+id/et_relative_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:hint="Message" >

</EditText> <Button android:id="@+id/btn_relative_ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:layout_below="@id/et_relative_msg" android:layout_alignRight="@id/et_relative_msg"/> <Button android:id="@+id/btn_relative_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel" android:layout_alignTop="@id/btn_relative_ok" android:layout_toLeftOf="@id/btn_relative_ok" android:layout_marginRight="10dp"/>

<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="相對父親居中" />

</RelativeLayout>

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="你好"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Hello"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="你好"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Hello"/>
</TableRow>

技術分享圖片

技術分享圖片

技術分享圖片

package com.example.toast_layout;

import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem;

////主界面MainActivity public class MainActivity extends Activity {

////程序已啟動回調用oncreate @Override protected void onCreate(Bundle savedInstanceState) {

//調用父類的onCreate方法進行 super.onCreate(savedInstanceState);

setContentView(R.layout.table_layout);//加載布局,並生成對應的視圖對象 } }

常用UI布局