zoukankan      html  css  js  c++  java
  • android中常用的布局管理器(二)

    接上篇博客

    (3)LinearLayout     线性布局管理器

           线性布局管理器是将放入其中的组件按照垂直或水平方向来布局,每一行或每一列只能放一个组件,并且不会换行,当组件排列到窗体的边缘后,后面的组件就不会显示出来。

         常用属性:

                 常用属性:
                       android:orientation(horizontal 水平,vertical 垂直)
                       android:gravity(对齐方式)     设置组件的对齐位置
                       android:layout_witdth(宽)       (默认为0,当输入一个大于0 的数字时,每个组件对父容器的剩余空间进行分割)
                       android:layout_height(高)
                       android:id
                       android:background(背景)

           案列:

    android:orientation="horizontal"     水平线性管理器
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        tools:context=".MainActivity">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮1"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮2"
             />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮3"
             />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮4" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮5" />
    </>
    

      

    android:orientation="vertical"    垂直水平管理器
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮1"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮2"
             />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮3"
             />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮4" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮5" />
    </>
    

      

    android:gravity="center"  设置组件的对其你方式
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center"
        tools:context=".MainActivity">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮1"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮2"
             />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮3"
             />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮4" />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮5" />
    </>
    

      

    android:layout_weight="1"     
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        tools:context=".MainActivity">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮1"
            android:layout_weight="1"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮2"
            android:layout_weight="1"
             />
    </>
    

      

    (4)FrameLayout     帧布局管理器

             帧布局(FrameLayout)在屏幕上开辟了一块区域,在这块区域中可以添加多个子控件,但是所有的子控件都会被对齐到屏幕的左上角。帧布局的大小由其下属子控件中尺寸最大的那个子控          件来控制。如果子控件的大小都一样,同一时刻只能看到最上面的子控件,其他的则被其遮挡(在进行选项卡设计时会用到帧布局)。

              注意:在FrameLayout中,子控件是通过栈来绘制的,所以后添加的子控件会被绘制在上层。

              FrameLayout继承自ViewGroup类,除了继承自父类的属性和方法,FrameLayout类中也包含了自己特有的一些属性和方法,见下表:

              

    属性名称 对应方法 描述
    android:foreground setForeground(Drawable) 设置绘制在所有子控件之上的内容
    android:foregroundGravity setForegroundGravity(int) 设置绘制在所有子控件之上内容的gravity属性
  • 相关阅读:
    makefile编写---单个子目录编译自动变量模板ok
    任务22:课程介绍 & 任务23:Http请求的处理过程
    任务20:DI初始化的源码解读 & 任务21:依赖注入的使用
    任务19:单元测试
    任务18:控制反转
    任务17:从UML角度来理解依赖
    任务16:介绍-
    任务15:配置框架设计浅析
    任务14:配置的热更新
    任务13:在Core Mvc中使用Options
  • 原文地址:https://www.cnblogs.com/zwx655/p/12256183.html
Copyright © 2011-2022 走看看