zoukankan      html  css  js  c++  java
  • android线性布局

    LinearLayout布局:

    android:orientation设置布局管理器内组件的排列方式,"vertical"垂直线性布局,"horizontal"水平线性布局

    android:gravity设置布局管理器内组件的对齐方式。

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

    <1>一个简单布局

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="bottom|center_horizontal"
         tools:context="com.example.practice.MainActivity" >
    
        <Button
            android:id="@+id/bn1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#3E5277"
            android:text="aaaaaaaa" />
    
        <Button
            android:id="@+id/bn2" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#52CB66"
            android:text="bbbbbbbb"
            />
        <Button
            android:id="@+id/bn3" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#CC0033"
            android:text="cccccccc"
            />   
    
    </LinearLayout>

    页面布局如图:

    <2>复杂一点的布局:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="bottom|center_horizontal"
          tools:context="com.example.practice.MainActivity" >
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
           android:orientation="horizontal"
        >
        <Button
            android:id="@+id/bn1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#3E5277"
            android:text="1" />
    
        <Button
            android:id="@+id/bn2" 
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="2"
            android:background="#52CB66"
            android:text="2"
            />
        <Button
            android:id="@+id/bn3" 
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="3"
            android:background="#CC0033"
            android:text="3"
            />   
            </LinearLayout>
            <LinearLayout 
              android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
              android:layout_weight="1"
              android:orientation="vertical" >
               
                <Button
            android:id="@+id/bn1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#3E5277"
            android:text="a" />
    
        <Button
            android:id="@+id/bn2" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="#52CB66"
            android:text="b"
            />
        <Button
            android:id="@+id/bn3" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:background="#CC0033"
            android:text="c"
            />   
            </LinearLayout>
    </LinearLayout>

    页面布局如图:

    android:orientation

    <3>其中特殊情况的布局:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="bottom|center_horizontal"
          tools:context="com.example.practice.MainActivity" >
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
           android:orientation="horizontal"
        >
        <Button
            android:id="@+id/bn1"
               android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#3E5277"
            android:text="1111111111111111" />
    
        <Button
            android:id="@+id/bn2" 
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#52CB66"
            android:text="22222222222222222222222"
            />
        <Button
            android:id="@+id/bn3" 
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="#CC0033"
            android:text="333333333333"
            />   
            </LinearLayout>
            <LinearLayout 
              android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
              android:layout_weight="1"
              android:orientation="vertical" >
               
                <Button
            android:id="@+id/bn1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#3E5277"
            android:text="a" />
    
        <Button
            android:id="@+id/bn2" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="#52CB66"
            android:text="b"
            />
        <Button
            android:id="@+id/bn3" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:background="#CC0033"
            android:text="c"
            />   
            </LinearLayout>
    </LinearLayout>

    页面布局如图:

  • 相关阅读:
    QT4.7.1 + VS2008 + QT Designer开发流程心得
    SharePoint 2010 托管元数据Bug (跟邮件提醒功能相关.小bug,大问题)
    SharePoint 2010 技巧系列: 控制Ribbon菜单权限(SiteActions的例子)
    发布一个SharePoint 2010 工具(复制,移动文件和文件夹)
    SHarePoint 2010 技巧 列验证 (column Validation)
    SharePoint 2010系列: 教你如何创建Internet 站点一 (设计母版页)
    SharePoint2010 技巧系列:快速开发Ribbon
    SharePoint 2010 技巧: 限制People Picker搜索非站点集内的用户
    SharePoint 2010 技巧系列 启用文档库接收邮件功能
    SharePoint 2010 技巧系列: 文档管理的自动分发功能
  • 原文地址:https://www.cnblogs.com/3120931037cnk/p/4886481.html
Copyright © 2011-2022 走看看