Android 将ImageView添加到ListActivity
我想在myAndroid 将ImageView添加到ListActivity,android,listview,layout,listactivity,Android,Listview,Layout,Listactivity,我想在myListActivity的myListView下添加一个ImageView。因此,当用户滚动到列表的末尾时,会显示ImageView 我的布局似乎不正确。要么根本不显示ImageView,要么如果我使用布局权重,则ListView和ImageView都会占据屏幕的50%。你知道我怎样才能得到我想要的吗?谢谢 <?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:android="http://sche
ListActivity的myListView
下添加一个ImageView
。因此,当用户滚动到列表的末尾时,会显示ImageView
我的布局似乎不正确。要么根本不显示ImageView
,要么如果我使用布局权重,则ListView
和ImageView
都会占据屏幕的50%。你知道我怎样才能得到我想要的吗?谢谢
<?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="fill_parent" >
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/list_no_items" />
<ImageView
android:id="@+id/instruct_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/instructions"/>
</LinearLayout>
不幸的是,我认为使用标准Android布局很难实现您想要实现的目标。在另一个滚动视图中不能有列表视图
您可以使用列表视图
页脚将图像视图
定位在列表视图下方
或者,您可以尝试将ImageView
添加为ListView中的最后一行。为此,请覆盖适配器的getView
方法,如果是最后一行,则返回ImageView
。我不能使用页脚,因为ImageView足够大,可以填充整个屏幕。我将尝试getView方法,尽管我不确定如何做到这一点。这应该是可能的,因为我成功地将图像添加到每个listview项目中,它提供了我想要的内容(除了图像显示了10次)。好的,您可以将ImageView配置为不占用整个屏幕。但如果你不希望它总是可见的,那就没有意义了。在ListView方法中,我会在适配器的末尾添加一个伪元素,然后在getView中检查if(isDummyElement())showImage()else showNormalListView()
。这仍然有点困难,但我想不出一个更干净的方法。好吧,在做了大量工作之后,我设法使用getView
来实现这一点。这看起来有点像一个黑客,但它正是我想要的。谢谢