Android的android:width和android:layout_width

看一个代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<!-- 依次定义7个TextView,先定义的TextView位于底层
    后定义的TextView位于上层 -->
<TextView android:id="@+id/View01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="210px"
    android:height="50px"
    android:background="#ff0000"
    />
<TextView android:id="@+id/View02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="180px"
    android:height="50px"
    android:background="#dd0000"    
    />
<TextView android:id="@+id/View03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="150px"
    android:height="50px"
    android:background="#bb0000"    
    />
<TextView android:id="@+id/View04"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="120px"
    android:height="50px"
    android:background="#990000"    
    />
<TextView android:id="@+id/View05"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="90px"
    android:height="50px"
    android:background="#770000"    
    />
<TextView android:id="@+id/View06"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="60px"
    android:height="50px"
    android:background="#550000"    
    />
<TextView android:id="@+id/View07"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="30px"
    android:height="50px"
    android:background="#330000"    
    />      
</FrameLayout>

效果图

这里写图片描述

从效果上面我们可以知道,android:width和android:height是设置内容的大小,最后还是会通过设置android:layout_widthandroid:layout_height来设置大小的!!!这也算是它们的区别。

如果你想直接指定控件大小,你可以通过android:layout_width和height设置:

<TextView android:id="@+id/View01"
    android:layout_width="272dp"
    android:layout_height="259dp"
    android:width="210px"
    android:height="50px"
    android:background="#ff0000"
    />

看效果图:

这里写图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值