我想在列表視圖的上方添加imageview。我知道在列表視圖中添加部分聽衆。但我只是想節省我的時間,所以我使用圖像視圖的ListView標題,而不是使用addSectionHeader。不幸的是,我只是堅持一些XML屬性。圖像覆蓋在我的列表視圖。其實圖像應該在列表的上方。檢查我的xml佈局。謝謝。在列表視圖的上方添加圖片
<?xml version="1.0" encoding="utf-8"?>
我想在列表視圖的上方添加imageview。我知道在列表視圖中添加部分聽衆。但我只是想節省我的時間,所以我使用圖像視圖的ListView標題,而不是使用addSectionHeader。不幸的是,我只是堅持一些XML屬性。圖像覆蓋在我的列表視圖。其實圖像應該在列表的上方。檢查我的xml佈局。謝謝。在列表視圖的上方添加圖片
<?xml version="1.0" encoding="utf-8"?>
此鏈接狀態與您的問題EditText wont display above ListView
使用相對佈局,具有約或低於列表視圖意見。
您可以告訴視圖以對齊頂部,底部,左側或右側,然後留有餘量爲其他視圖騰出空間。
例如,如果你想在你的列表視圖下面顯示一個圖像,你可以將你的列表視圖對齊到父視圖頂部,並將一個底部邊界分配給列表視圖。然後將imageview對齊父級底部,並從列表視圖的邊距將爲它騰出空間。
希望這是有道理的。
編輯:
下面是一些代碼:我剛纔寫的我的頭頂部,以便驗證標籤的屬性,但應該給你的想法。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent" >
<ListView
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginBottom="50dp"
android:layout_alignParentTop="true" />
<TextView
android:text="Some text"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true" />
</RelativeLayout>
編輯完成後,我的答案看起來不正確,但是您可以使用頂部邊距來做同樣的事情。 – trgraglia 2011-03-21 10:59:15
試試這個代碼:
TextView tv1=new TextView(context);
Resources res=getResources();
Drawable d1=res.getDrawable(R.drawable.YourImage);
tv1.setBackgroundDrawable(d1);
ListView.addHeaderView(tv1);
要添加的上方或下方的圖像,標題說以下列表視圖的,說明上面說的listview!? – sat 2011-03-21 10:51:22
**更新**對不起我的壞。已經改變。謝謝 – geekmyo 2011-03-21 10:53:01