android:id="@+id/android:empty属性的用法举例

今天在一个布局文件中看见如下内容:

[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     android:gravity="center_horizontal">  
  7.       
  8.     <ListView android:id="@+id/android:list"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="fill_parent" />  
  11.   
  12.     <TextView android:id="@+id/android:empty"  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"   
  15.         android:layout_marginTop="130px"  
  16.         android:textSize="25px"  
  17.         android:text="@+string/textview_text"/>  
  18.     <Button   
  19.         android:id="@+id/Button01"   
  20.         android:layout_width="200px"   
  21.         android:layout_height="wrap_content"  
  22.         android:layout_marginTop="50px"  
  23.         > </Button>  
  24. </LinearLayout>  

先说效果,当ListView不为空时,只显示listview;反之显示TextView 和Button。

这跟java文件里的代码没有关系,是由TextView的android:id="@+id/android:empty属性实现的。


TextView的android:id="@+id/android:empty属性决定当ListView为空时自动显示TextView。忽略

流式布局里的ListView 的存在。认为整个布局里只有TextView 和Button,为此两个都能显示出来。


注释掉TextView后,不论ListView是否是空的,都不能显示Button。因为ListView的高度为fill_parent,

故Button也没有显示出来。此时把ListView的高度修改成wrap_content,就会显示出Button来了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值