请问,如何在一个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不显示出来
下面是我的代码
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不显示出来
解决方案 »
- 如何在模拟器system/app中安装自己的apk
- weather应用crash问题
- 请问,遇到了Android上动画类(AnimationDrawable)不能切换图片的问题,该如何解决。
- Android初学-如何在布局文件中把TextView的内容放在中央
- Android SDK 安装耗时如何解决??????????
- ImageButton 或 EditText ,如何控制其显示或隐藏呢?
- android studio 配置问题
- android IPC通信问题,关于bundle中传递非基本数据类型报错: Class not found when unmarshalling
- 学习android的新手,在做例子中不断前行,感谢大家给我帮助,这里遇到了一个问题,恳请各位大哥大姐指教!
- android 蓝牙BLE操作时,不同手机连接速度不一样,求大神帮忙解决一下。。。
- android里面如何实现各种绘字的效果
- eclipse文件没有错误,但是文件夹报错,很纠结啊
<TextView android:id="@+id/fontsetTextView"
android:layout_width="120px" 这个改成<TextView android:id="@+id/fontsetTextView"
android:layout_width="fill_parent"
用相对布局吧 ,试试这个
<?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>