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,特点是可以被按中和不按中的状态,而且在按中的时候跟未按中的时候分别可以显示不同的文本。

  • 相关阅读:
    0918作业-----所有数值未做合法性检测
    尝试安装和配置JDK,并给出安装、配置JDK的步骤
    java为什么可以跨平台执行
    字符集
    java 入门及简介
    时间轴特效
    javascript简介
    javascript while循环
    Javascript for循环
    函数豹子问题
  • 原文地址:https://www.cnblogs.com/zhai1997/p/12680956.html
Copyright © 2011-2022 走看看