登陆界面 LinearLayout的属性的用法

通过设计登录界面的实例来了解LinearLayout一些属性的用法


要点:

android:orientation="vertical"垂直线性布局,"horizontal"水平线性布局

android:gravity="top"(buttom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal)控制布局中控件的对齐方式。如果是没有子控件的控件设置此属性,表示其内容的对齐方式,比如说TextView里面文字的对齐方式;若是有子控件的控件设置此属性,则表示其子控件的对齐方式,gravity如果需要设置多个属性值,需要使用“|”进行组合

android:gravity 与 android:layout_gravity的区别
android:gravity是指定本元素的子元素相对它的对齐方式。
android:layout_gravity是指定本元素相对它的父元素的对齐方式。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

   
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:orientation="vertical" >
	
        <!-- 标题 -->
        <!-- android:gravity="center"  因为有子控件,所以作用是设置子控件在本控件中的位置 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:gravity="center" 
            android:orientation="vertical" >
		<!--  android:gravity="center"  因为没有子控件,所以作用是设置文字在TextView中的位置 -->
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center" 
                android:text="淘宝客户端"
                android:textSize="25sp"/>
          

		</LinearLayout>

        <!-- 内容 -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:padding="5dp" >
			<!-- layout_weight="3"使TextView占宽度的1/4  layout_weight="1"使EditText占比重的3/4-->
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="3"
                android:gravity="center"
                android:text="账 号"
                android:textSize="18sp" />



            <EditText
                android:id="@+id/zhanghao"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:hint="输入账号名"
                android:textSize="18sp" />

        </LinearLayout>
		<!-- android:padding="5dp" 使子控件距离边缘5dp -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="5dp" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="3"
                android:gravity="center"
                android:text="密 码"
                android:textSize="18sp" />

            <EditText
                android:id="@+id/zhanghao"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:hint="输入密码"
                android:textSize="18sp" />
        </LinearLayout>

        <!-- 按钮 -->
        
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:gravity="center"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/login"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:text="登录" />

            <Button
                android:id="@+id/login"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:text="注册" />

       </LinearLayout>
    </LinearLayout>

</LinearLayout>



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值