当前位置: 代码迷 >> Android >> Android开发之RelativeLayout跟RableLayout
  详细解决方案

Android开发之RelativeLayout跟RableLayout

热度:23   发布时间:2016-05-01 13:04:01.0
Android开发之RelativeLayout和RableLayout

      这几天学习andriod的布局,总体感觉,linearLayout和TableLayout都相对简单一点,而RelativeLayout稍微复杂一点,所以贴出来让大家看看,如下是布局图

如下是main.xml文件的内容<?xml version="1.0" encoding="utf-8"?>

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    ><TextView 	android:id="@+id/label" 	android:text="URL:"    android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignBaseline="@+id/edit"    android:layout_alignParentLeft="true"    /><EditText	android:id="@+id/edit"	android:layout_width="fill_parent"	android:layout_height="wrap_content"	android:layout_toRightOf="@id/label"	android:layout_alignParentTop="true"/><Button	android:id="@+id/ok"	android:layout_width="wrap_content"	android:layout_height="wrap_content"	android:layout_below="@id/edit"	android:layout_alignRight="@id/edit"	android:text="OK"	/><Button	android:id="@+id/cancel"	android:text="Cancel"	android:layout_width="wrap_content"	android:layout_height="wrap_content"	android:layout_toLeftOf="@id/ok"	android:layout_alignTop="@id/ok"	/></RelativeLayout>

如果用TableLayout来表示上述图的话,更加简洁,代码如下

<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:stretchColumns="1"    >    <TableRow>    	<TextView 		    		android:text="URL"    		/>    	<EditText    		android:id="@+id/entry"    		android:layout_span="3"    		/>    </TableRow>    <View    	android:layout_height="2px"    	android:background="#0000FF"    	/>    <TableRow>    	<Button    		android:id="@+id/cancel2"    		android:text="Cancel"    		android:layout_column="2"    		/>    	<Button    		android:id="@+id/ok2"    		android:text="OK"    		/>    </TableRow></TableLayout>




  相关解决方案