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

[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来了。

更多相关文章

  1. Android Layout属性笔记
  2. Android学习—LinearLayout布局中实现左右对齐
  3. android常用的一些属性说明
  4. Android布局控件属性
  5. Android布局文件中常用的属性
  6. Android:TextView属性

随机推荐

  1. android 使用服务读取串口数据实例
  2. [原]Android应用程序绑定服务(bindService
  3. Android中使用Notification
  4. android设备的内存空间(RAM)总空间和可用
  5. Android开发已经没人要了么?
  6. iOS开发周报:Swift 项目合并 Android 分支
  7. Android之assets资源目录的各种操作
  8. android studio中如何导入github项目
  9. [置顶] android adapter
  10. Apple IOS、Android、WebOS系统体系架构