温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

android的LinearLayout布局

发布时间:2020-10-06 15:07:02 来源:网络 阅读:357 作者:matengbing 栏目:移动开发
<?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:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="@string/message" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/send" />
</LinearLayout>
<!--    android:orientation="vertical" 代表方向垂直-->
<!--  android:layout_weight="1" 代表所占权重(比例)    message占满其他元素剩余的地方,
		如果有多个android:layout_weight=1,则平分剩余空间
		 android:gravity="top"表示从上面开始占(写了android:layout_weight的)
		 
		 
		   android:layout_gravity="right"
		   整个组件的位置居右
-->

android的LinearLayout布局

<?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:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="horizontal" >
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/to" />
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/subject" />
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="@string/message" />
    <Button
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="@string/send" />
</LinearLayout>

android的LinearLayout布局

LinearLayout 是一个视图组,它所有的子视图都在一个方向对齐,水平或者垂直。你可以指定布局的方向通过 android:orientation 属性。

LinearLayout的所有子视图排列都是一个靠着另一个,因此垂直列表每行仅仅有一个子视图,不管有多宽。水平列表只能有一行的高度(最高子视图的高度加上边距距离)。LinearLayout 期望子视图之间都有margin,每个子视图都有gravity

线性布局支持给个别的子视图设定权重,通过android:layout_weight属性。就一个视图在屏幕上占多大的空间而言,这个属性给其设定了一个重要的值。一个大的权重值,允许它扩大到填充父视图中的任何剩余空间。子视图可以指定一个权重值,然后视图组剩余的其他的空间将会分配给其声明权重的子视图。默认的权重是0.

例如,如果有三个文本框,其中两个声明的权重为1,另外一个没有权重,没有权重第三个文本字段不会增加,只会占用其内容所需的面积。其他两个同样的会扩大以填补剩余的空间,在三个文本域被测量后。如果第三个字段,然后给定的权重为2(而不是0),那么它现在的声明比其他的更重要,所以它得到一半的总的剩余空间,而前两个平均分配剩余的。



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI