A​n​d​r​o​i​d​ 简单布局LinearLayout、table、frame、relative

来源:互联网 发布:如何防止盗取网页源码 编辑:程序博客网 时间:2024/06/07 01:55

源码下载↓↓↓

基本的布局方式,做了几个测试,都是属性配置什么的。不需要说明,直接上代码:

线性布局-LinearLayout:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:id="@+id/textView1"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:gravity="right"        android:text="TextView" />    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="C" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="+/-" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="/" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="*" />    </LinearLayout>    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="7" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="8" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="9" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="-" />    </LinearLayout>    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="4" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="5" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="6" />        <Button            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="+" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="93dp"        android:layout_weight="1"        android:orientation="horizontal" >        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:orientation="vertical" >            <LinearLayout                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:orientation="horizontal" >                <Button                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text="1" />                <Button                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                      android:layout_weight="1"                    android:text="2" />                <Button                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                      android:layout_weight="1"                    android:text="3" />            </LinearLayout>            <LinearLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:orientation="horizontal" >                <Button                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:layout_weight="1"                    android:text="0" />                <Button                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:layout_weight="2"                    android:text="." />            </LinearLayout>        </LinearLayout>        <Button            android:layout_width="match_parent"            android:layout_height="99dp"            android:layout_weight="3"            android:text="=" />    </LinearLayout></LinearLayout>
frame布局:


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >    <ImageView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="@drawable/big"        android:layout_gravity="center"                android:text="button" />    <ImageView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="@drawable/qie"        android:layout_marginTop="100dp"        android:text="button" />    <ImageView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="@drawable/juhua"        android:layout_marginLeft="100dp"        android:text="button" /></FrameLayout>
相对布局-relative:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <Button        android:id="@+id/button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerInParent="true"        android:text="button" />   <Button        android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_above="@id/button"        android:layout_toLeftOf="@id/button"        android:text="button1" />    <Button        android:id="@+id/button2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_above="@id/button"        android:layout_toRightOf="@id/button"        android:text="button2" />    <Button        android:id="@+id/button3"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/button"        android:layout_toRightOf="@id/button"        android:text="button3" />    <Button        android:id="@+id/button4"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/button"        android:layout_toLeftOf="@id/button"        android:text="button4" /></RelativeLayout>

table布局:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" ><TableLayout     android:layout_width="fill_parent"   android:layout_height="wrap_content"    android:stretchColumns="0,1,2,3">    <TableRow >        <Button       android:id="@+id/button1"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:text="button1" />        <Button       android:id="@+id/button2"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:text="button2" />        <Button       android:id="@+id/button3"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:text="button3" />        <Button       android:id="@+id/button4"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:text="button4" />    </TableRow></TableLayout><TableLayout     android:layout_width="fill_parent"   android:layout_height="wrap_content"    android:stretchColumns="0">    <TableRow           android:layout_width="fill_parent"       android:layout_height="fill_parent">        <EditText       android:id="@+id/button1"       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:gravity="center"       android:text="button1" />    </TableRow></TableLayout></LinearLayout>
点击下载源码


0 0
原创粉丝点击