常用UI布局

<?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);//加载布局,并生成对应的视图对象  } }

猜你喜欢

转载自www.cnblogs.com/feng8026/p/9021469.html