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="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"
		   整个组件的位置居右
-->

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

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

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

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

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

时间: 2024-07-29 20:35:40

android的LinearLayout布局的相关文章

Android学习——LinearLayout布局实现居中、左对齐、右对齐

android:orientation="vertical"表示该布局下的元素垂直排列: 在整体垂直排列的基础上想要实现内部水平排列,则在整体LinearLayout布局下再创建一个LinearLayout布局. 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/r

Android:LinearLayout布局中Layout_weight的深刻理解

首先看一下LinearLayout布局中Layout_weight属性的作用:它是用来分配属于空间的一个属性,你可以设置他的权重.很多人不知道剩余空间是个什么概念,下面我先来说说剩余空间. 看下面代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" an

15.Android中LinearLayout布局一些小记录

在App中,我们经常看到布局中会有分割线,直接上代码: 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height=

android基础之LinearLayout布局

LinearLayout布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="matc

Android五种布局方式——LinearLayout、RelativeLayout、TableLayout....(四)

Android五种布局方式--LinearLayout.RelativeLayout .TableLayout.... Android使用XML声明界面布局 将程序的表现层和控制层分离 修改用户界面时,无需更改程序的源代码 可视化工具设计用户界面 Android五种布局方式 LinearLayout线性布局 AbsoluteLayout坐标布局 RelativeLayout相对布局 FrameLayout帧布局 TableLayout表格布局 GridLayout 1.LinearLayout线

Android入门开发之Linearlayout布局(七)

前言 上一节我们主要讲解了linux下的权限说明,今天我们来了解一下Android中的UI设计,聊聊android中常用的布局. android中的布局主要有六种,分别是线性布局(LinearLayout),相对布局(Relativelayout),帧布局(FrameLayout),网格布局(GridLayout)以及绝对布局(AbsoluteLayout)和表格布局(TableLayout),在这六种布局中,我们比较常用的就是线性布局和相对布局以及帧布局,所以在布局方面,我打算主要围绕这三个布

android学习——LinearLayout线性布局

LinearLayout线性布局 LinearLayout是一种线型的布局方式.LinearLayout布局容器内的组件一个挨着一个地排列起来:不仅可以控制个组件横向排列,也可控制各组件纵向排列.通过orientation属性设置线性排列的方向是垂直(vertical)还是纵向(horizontal). 我们下面通过XML布局和Java代码布局两种方式分别举例: 一.XML方式布局 1.创建一个空白Activity 2.打开“res/layout/activity_main.xml”文件,修改成

Android LinearLayout布局的layout_weight属性探究

Android布局文件中的layout_weight属性仅在LinearLayout布局中有效. google推荐:当设置了控件的layout_weight属性时,该控件相应的layout_width或者layout_height属性应该设置为0dp. 如果设置了控件的layout_weight属性同时,又设置了layout_width或者layout_height属性,此时有多种情况需要分析,(可能某些控件设置了layout_weight属性,某些没有设置,设置了layout_weight属性

Android——ListView多布局+适配器(二)

Android--ListView多布局+适配器(二) <span style="font-size:18px;">package com.example.administrator.newstop.entity; /** * Created by Administrator on 2016/8/4. */ public class News { private String title; private String pubDate; private int img; p