zoukankan      html  css  js  c++  java
  • 布局TextView和EditText区别,layout_width和lay_weight区别--Android Studio

    1. TextView控件是文本表示控件,主要功能是向用户展示文本的内容,它是不可编辑的,如设置标题;EditText控件是编辑文本控件,主要功能是让用户输入文本的内容,它是可以编辑的。
    每一个控件都有着与之相应的属性,通过选择不同的属性,给予其值,能够实现不同的效果。
    2. layout_width属性值设置为wrap_content时,获得的空间仅够描绘自身,还有额外的空间。layout_weight的属性值进行额外的空间分配。
    如果layout_width="0dp",则只考虑layout_weight属性值。
    <LinearLayout
        android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp">

    <Button
    android:text="Button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/crime_date"
    android:layout_weight="1"
    />
    <CheckBox
    android:id="@+id/crime_solved"
    android:text="@string/crime_solved_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_weight="1"/>
    </LinearLayout>
    如代码:LinearLayout有两个控件,Button 和CheckBox.

    第一步查看layout_width属性值(竖直方向则查看layout_height)。因为设置为wrap_content时,获得的空间仅够描绘自身,还有额外的空间。
    第二步LinearLayout依据layout_weight的属性值进行额外的空间分配。两个子组件属性值同为1。因为均分了同样大小的额外空间。若设Button的layout_weight的值为2,则将获得2/3的额外空间,
    CheckBox组件获得剩余的1/3。







  • 相关阅读:
    c# 第41节 异常处理
    c# 第40节 密封类、密封方法
    c# 第39节 抽象类、抽象方法
    c# 第38节 接口的实现
    c# 第37节 接口的实现与继承
    c# 第36节 接口的声明
    测试面试题集-接口测试
    Python接口自动化测试系列文章汇总
    Jmeter系列之简介与环境安装
    Python接口自动化之logging封装及实战
  • 原文地址:https://www.cnblogs.com/phpli/p/5945311.html
Copyright © 2011-2022 走看看