zoukankan      html  css  js  c++  java
  • 安卓:CompoundButton、布局(LinearLayout、RelativeLayout)

    1、安卓中的布局

    Android提供了一些预定义的ViewGroup子孙类,常用的有 LinearLayout(线性布局),RelativeLayout(相对布局),TableLayout(表格布局) FrameLayout(帧布局),AbsoluteLayout(绝对布局),GridLayout(网格布局) 。
    定义UI布局的最常用的方法是使用XML布局文件,如同HTML一样,XML为布局提供了一种可读的结构。XML中的每个元素都是View或ViewGroup的子孙类的对象,可以把每一个XML布局文件理解为一棵由View和ViewGroup的子孙类对象组成的树,树根是一个ViewGroup对象,所有的叶节点都是View对象,树的分支节点都是ViewGroup对象。

    2、LinearLayout

    (1)layout_weight:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    
        <LinearLayout    
            android:layout_width="0dp"    
            android:layout_height="fill_parent"    
            android:background="#ADFFeF"     
            android:layout_weight="1"/>    
           
            
        <LinearLayout    
            android:layout_width="0dp"    
            android:layout_height="fill_parent"    
            android:background="#DA70e6"     
            android:layout_weight="2"/>   
    
    </LinearLayout>

    效果:

     layout_weight是水平方向显示的宽度的比例。

    3、RelativeLayout

    (1)父容器定位

    (2)兄弟组件定位

    4、CompoundButton家族

    (1)CheckBox:两种状态,复选框,可以调用setOnCheckedChangeListener()方法来处理事件

     (2)RadioButton:单选框,需要使用RadioGroup来组织多个RadioButton,在一个RadioGroup中,一次只能选中一个RadioButton

     (3)ToggleButton:两种状态,常用于表示开关场景中,不同于Button,特点是可以被按中和不按中的状态,而且在按中的时候跟未按中的时候分别可以显示不同的文本。

  • 相关阅读:
    c中uint32转为string
    linux中查找某类文件中的特定字符串
    VMWare Workstation 无法连接外部设备
    Evernote(印象笔记)无法登录的问题
    Python request 在linux上持续并发发送HTTP请求遇到 Failed to establish a new connection: [Errno 11] Resource temporarily unavailable
    设计模式
    jquery-ui sortable 在拖动换位置时改变元素的大小导致占位与实际不一致
    Appium IOS 使用多模拟器并发执行测试
    Fiddler脚本修改Response数据
    android style和attr的用法
  • 原文地址:https://www.cnblogs.com/zhai1997/p/12680956.html
Copyright © 2011-2022 走看看