请问,如何在一个ListView控件下面增加一个控件,比如我要在ListView之后添加一个TextView呢?
下面是我的代码
main.xml
<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:paddingLeft="8dp"
         android:paddingRight="8dp">     <ListView android:id="@+id/android:list"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:background="#00FF00"
               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>     <TextView android:id="@id/android:empty"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:background="@drawable/white"
               android:text="No data"/>
 </LinearLayout>
item.xml<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
>
         
<ImageView
android:id="@+id/fontsetImageView"
android:src="@drawable/set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@color/black"
></ImageView><TextView android:id="@+id/fontsetTextView" 
android:layout_width="120px" 
android:layout_height="wrap_content" 
android:textSize="20px" 
android:textColor="@color/black"
android:layout_toRightOf="@id/fontsetImageView"
/> 

</RelativeLayout>
MyListActivity.javapublic class FontTab extends ListActivity{ private ListView listView;
public void onCreate(Bundle bundle){

super.onCreate(bundle);
this.setContentView(R.layout.main);
//设置显示字体的属性
init();
}

//font属性设置项
private String[] fontSet = {"返回", "字体大小", "字体类型", "字体颜色",};
//初始化列表
public void init(){
SimpleAdapter adapter = new SimpleAdapter(this, getData( fontSet), R.layout.fontset,
new String[]{"text", "img"}, new int[]{R.id.item, R.id.fontsetImageView});
setListAdapter(adapter);
}
}只能显示列表, TextView不显示出来

解决方案 »

  1.   

    把你textview的
    <TextView android:id="@+id/fontsetTextView" 
    android:layout_width="120px" 这个改成<TextView android:id="@+id/fontsetTextView" 
    android:layout_width="fill_parent" 
      

  2.   


    用相对布局吧 ,试试这个
    <?xml version="1.0" encoding="utf-8"?>
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:paddingLeft="8dp"
             android:paddingRight="8dp">     <ListView android:id="@+id/android:list"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:background="#00FF00"
                   android:layout_weight="1"
                   android:drawSelectorOnTop="false" android:layout_above="@id/empty"/>     <TextView android:id="@id/android:empty"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:background="@drawable/white"
                   android:text="No data"/>
     </RelativeLayout>