安卓线性布局(属性)

安卓六大布局:

AbsoluteLayout  绝对布局(已过期,不建议使用)

RelativeLayout    相对布局

LinearLayout       线性布局

FrameLayout       帧布局

TableLayout        表格布局 (是LinerLayout的子类)

GridLayout            网格布局(4.0推出)

安卓目前使用的布局UI控件网状图:(该图箭头所指向的是其父类)




目前推荐使用RelativeLayoutLinearLayout;FrameLayout三个布局

<1>线性布局    LinearLayout布局

线性布局控制其中的控件按照横向或纵向方式排列,并且线性布局不会换行,当控件

排列到窗体边缘,后面的控件就被隐藏,不会被显示出来。

线性布局的默认方向是水平方向(Hoizontal)

线性布局的属性:      match parent :匹配父容器的大小

                             wrap content :根据容器内的东西决定组件的大小

                             android:orientation(确定方向):定义布局内控件或组件的排列方式  vertical(垂直)horizontal(水平)

                             android:background: 设置控件的背景颜色或背景图片

                             android:id                设置控件的Id。这样就可以在R.java中生成相应的值,在程序中通过findViewById就可以调用                                                    android:id = "@+id/id的名字"

                             gravity                        android:gravity="center":指定当前控件中内容(子控件)的对齐方式   

                                                               android:layout_gravity="center":当前控件在其父控件中的对齐方式

    代码注释:

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

<!-- LinearLayout:线性布局,只能沿着水平或者垂直一个方向摆放控件,默认是沿着水平方向摆放控件 android:orientation="horizontal":水平方向,只能沿着水平方向摆放控件(一列只能放一个控件),是默认值 android:orientation="vertical":垂直方向,只能沿着垂直方向摆放控件(一行只能放一个控件) android:layout_width="match_parent" -->

-<LinearLayout android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">

<!-- android:layout_weight="1":权重(比例),如果不设置,权重值默认为0,默认情况下,手机渲染控件时,会首先 显示权重值小的控件,然后在显示稍大一点的控件 当线性布局的方向为垂直方向时,如果指定控件的高度是match_parent,则此时指定控件的权重值和其占据空间大小成反比. 当线性布局的方向为垂直方向时,如果指定控件的高度是wrap_content,则此时指定控件的权重值和其占据空间大小成正比. -->


<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="One" android:textSize="30sp" android:background="@color/colorAccent" android:layout_weight="1"/>

<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Two" android:textSize="30sp" android:background="@color/colorPrimary" android:layout_weight="2"/>

<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Three" android:textSize="30sp" android:background="@android:color/holo_red_dark" android:layout_weight="3"/>

</LinearLayout>

TextView:文本显示控件

android:text:显示提示信息文本

EditText:文本输入控件,可以让用户输入自己的内容

android:hint=“请输入用户名”:当用户没有输入任何内容时显示的提示文本,用户一旦输入则提示文本自动消失,删除输入的字符后提示文本自动显示

android:id = "@+id/editText_userName"  :将添加R类中的editText_userName静态内部类中的userName静态常量






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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值