Android线性布局LinearLayout(七)

一、先了解几个属性:

1.布局

1) android:orientation="vertical" 垂直布局

2)android:orientation="horizontal"  水平布局

2.控件内容高和宽布局

1) android:layout_width="match_parent" ,布满整个屏幕. [匹配父窗口]

2)android:layout_height="wrap_content",布局元素将根据内容更改大小.[内容包括]

3.布局比例

所有的视图都有一个layout_weight值,默认为零,意思是需要显示 多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视 图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight 值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布 局的layout_weight值中所占的比率而定。

二、下面两个例子实现:

1)三个按钮横向摆放

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="mc" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="m+" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="m-" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="mr" />
    </LinearLayout>

借用layout_weight使三个按钮摆放占用比例一致.

二、两层按钮:第一层三个,第二次2个

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:orientation="horizontal" >

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="1" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="2" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="3" />
        </LinearLayout>

           <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:orientation="horizontal" >

                  <Button
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:text="0" />

            <Button
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="." />
             </LinearLayout>
    </LinearLayout>

先用一个大层,设置权重比例都是3. 第二层的第一个按钮比例的权重又占它属于层的2/3.

时间: 2024-08-05 07:31:42

Android线性布局LinearLayout(七)的相关文章

Android 自学之线性布局 LinearLayout

线性布局(LinearLayout),线性布局有点想AWT编程里面的FolwLayout,他们都会将容器里面的组件挨个的排列起来. 他们最大的区别在于:Android的线性布局不会换行:AWT里面的FolwLayout则会另起一行进行显示 LinearLayout支持常用XML属性及相关方法的说明 XML属性 相关方法 说明 android:gravity setGravity(int) 设置布局管理器内组件的对齐方式.该属性支持top,bottom,left,right--也可以同时制定多种对

Android 线性布局(LinearLayout)相关官方文档 - 指南部分

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. Android 官方文档线性布局相关资源链接汇总如下: android-sdk-macosx-4.4.2/docs/guide/topics/ui

Android 线性布局(LinearLayout)相关官方文档 - 参考部分

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. Android 官方文档线性布局相关资源链接汇总如下: android-sdk-macosx-4.4.2/docs/guide/topics/ui

Android线性布局实现聊天气泡+多样化图层效果

Android线性布局实现聊天气泡+多样化图层效果                                                                      支持平台:Android    运行环境:Eclipse    开发语言:Java                                                                      下载地址:http://www.devstore.cn/code/info/222.ht

线性布局LinearLayout

线性布局LinearLayout 一.简介 LinearLayout是一种线型的布局方式.LinearLayout布局容器内的组件一个挨着一个地排列起来:不仅可以控制个组件横向排列,也可控制各组件纵向排列.通过orientation属性设置线性排列的方向是垂直(vertical)还是纵向(horizontal). 线性布局实例 二.代码实例 效果图: 代码:

Android布局之线性布局——LinearLayout

本文将详细介绍线性布局的各种xml属性. xml属性 <?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="mat

Android——布局(线性布局linearLayout,表格布局TableLayout,帧布局FrameLayout)

线性布局: <?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="match_parent&q

android之线性布局LinearLayout以及weight权重使用

LinearLayout(线性布局): :layout/activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:lay

Android 线性布局(LinearLayout)性能相关

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 如下嵌套线性布局中有两处性能问题,在不使用 Eclipse Adt 提示的情况下,你能找得出来吗? <LinearLayout xmlns: