布局layout

 

布局layout

   布局分为:线性布局(linear_layout)、相对布局(relative_layout)、表格布局(table_layout).

android:layout_centerHrizontal  水平居中
android:layout_centerVertical 垂直居中

登录页面,不同方式代码:

表格布局

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:stretchColumns="1" >

<TableRow >

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/system" />

   

    </TableRow>

   

   

     <TableRow >

   

     <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/username" />

  <EditText

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

   

         />

   

    </TableRow>

   

        

        

     <TableRow >

   

     <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/userpass" />

  <EditText

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

           />

        </TableRow>

           <TableRow >

            <Button  

             android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            

            android:text="@string/login"

           

            android:id="@+id/login_id"

            />

        <Button  

              android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            

            android:text="@string/cancel"

           android:id="@+id/cancel_id"

           />

     </TableRow>

 

</TableLayout>

相对布局

 

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

 

   

    <TextView   

       

         android:layout_width="fill_parent"

          android:layout_height="wrap_content"

         

          android:text="@string/system"

         

        android:id="@+id/t1_id"

       

        />

   

   

     <TextView 

           

             android:layout_width="wrap_content"

          android:layout_height="wrap_content"

         

          android:text="@string/username"

         

          android:layout_below="@id/t1_id"

        

         android:id="@+id/name_id"

           

            />

   

    <EditText

            android:layout_width="fill_parent"

            android:layout_height="30px"

           

            android:layout_toRightOf="@id/name_id"

            android:layout_below="@id/t1_id"

            android:id="@+id/e1_id"

           ></EditText>

   

       

        <TextView 

                     android:layout_width="wrap_content"

          android:layout_height="wrap_content"

         

          android:text="@string/userpass"

          android:id="@+id/pass_id"

          android:layout_below="@id/name_id"

            />

        <EditText

            android:layout_width="fill_parent"

            android:layout_height="30px"

            android:layout_below="@id/e1_id"

            android:layout_toRightOf="@+id/pass_id"

                       android:id="@+id/e2_id"

           

            />

         <Button

                android:layout_width="wrap_content"

          android:layout_height="wrap_content"

                android:text="@string/cancel"

               

                android:layout_below="@id/e2_id"

                android:layout_alignParentRight="true"

                android:id="@+id/cancel_id"

                />

    <Button

                android:layout_width="wrap_content"

          android:layout_height="wrap_content"

                android:text="@string/login"

                 android:layout_below="@id/e2_id"

                android:layout_toLeftOf="@id/cancel_id"

                                />

</RelativeLayout>

  嵌套布局:

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

    <TextView   

             android:layout_width="fill_parent"

          android:layout_height="wrap_content"

                  android:text="@string/system"

               />

        <RelativeLayout

               android:layout_width="fill_parent"

          android:layout_height="wrap_content"

               />

         <TextView 

                       android:layout_width="wrap_content"

          android:layout_height="wrap_content"

                   android:text="@string/username"

                 android:id="@+id/name_id"

                       />

               <EditText

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

           

            android:layout_toRightOf="@id/name_id"

           

            android:id="@+id/e1_id"

           >

        </EditText>

             </RelativeLayout>   

               <RelativeLayout

                 android:layout_width="fill_parent"

          android:layout_height="wrap_content"

               / >

             <TextView 

                     android:layout_width="wrap_content"

          android:layout_height="wrap_content"

                    android:text="@string/userpass"

          android:id="@+id/pass_id"

            />

               <EditText

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

                       android:layout_toRightOf="@+id/pass_id"

                      />

          </RelativeLayout>

         <RelativeLayout

                 android:layout_width="fill_parent"

          android:layout_height="wrap_content"

               />       

                    <Button

                android:layout_width="wrap_content"

          android:layout_height="wrap_content"

                android:text="@string/cancel"

                                android:layout_alignParentRight="true"

                android:id="@+id/cancel_id"

                />

                      <Button

                android:layout_width="wrap_content"

          android:layout_height="wrap_content"

                android:text="@string/login"

                android:layout_toLeftOf="@id/cancel_id"

                               />

                </RelativeLayout>

</LinearLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值