2009-09-04 103 views
62

如何在Android中使ListView透明?如何在Android中使ListView透明?

背景的android屏幕圖像應該是可見的。

+14

能否請您標記正確的答案 – 2010-06-15 08:13:54

+2

請標記出哪個答案是正確的,因爲它非常有用的問題。 – Naruto 2012-04-29 13:29:20

+0

最好的方法你會找到它:http://nikshits.wordpress.com/2011/11/29/code-to-make -listview-transparent/ – 2013-01-03 17:49:03

回答

59

的android:背景= 「@安卓:彩色/透明」 機器人:cacheColorHint = 「@安卓:彩色/透明」

+12

有關更詳細的解釋:http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html – tonys 2010-12-23 11:59:49

+0

爲什麼不使用@android:color /反式父母代替#00000000? – ademar111190 2013-08-18 09:29:12

13
  • 如何讓ListView的android系統是否透明?

如張學友提到的,列表視圖將做的工作設置屬性。

android:background="#00000000" 
android:cacheColorHint="#00000000" 
  • 背景的android屏幕圖像應該是可見的。

在Android清單文件中添加下列屬性的活動。

android:theme="@android:style/Theme.Dialog" 
+0

爲什麼不使用@android:color/transparent改爲#00000000? – ademar111190 2013-08-18 09:29:52

122

你應該使用了更詳細

android:background="@android:color/transparent" 
android:cacheColorHint="@android:color/transparent" 

與張學友的響應更新。我原本只是想補充他的回答,因爲他在樣本中使用了簡單的十六進制顏色。

+3

這已經很晚了,但對於來這裏的人來說,請看下面的Jacky的回答。沒有設置android:cacheColorHint屬性,結果非常難看。 – 2011-06-05 02:02:45

+0

資源未找到錯誤上升..所以,你能幫助 – 2011-09-21 12:45:39

+0

這是因爲你不應該使用「更詳細」。馬蒂亞斯基本上通過竊取他的回答並添加了一個多餘的複雜性而剝奪了Jacky。基本上@android:color/transparent ==#00000000,唯一的區別是,編譯器不必具有靜態十六進制值,而是必須查找該資源並插入值本身。 – 2012-04-17 01:46:14

1

的答案上面會工作,但有一個機會,當你滾動listView,它會變暗,就像在這種情況下:android-listview problem with transparent cells

要解決此問題,您可以使用cac heColorHint,如上所述,但如果您動態添加ListView(從代碼而不是xml),那麼這將不起作用。你不得不用XML來聲明ListView,不知道這是一個錯誤還是別的。

5

試試這個:

list.setCacheColorHint(Color.TRANSPARENT); 
5

加入本作列表項留透明按下時:

android:listSelector="@android:color/transparent" 
1

試試這個:

android:cacheColorHint="@null" 
3

如果您想使用部分透明,這將幫助您設置顏色代碼。

2個十六進制字符可以被附加到任何十六進制顏色代碼。 8位十六進制顏色代碼中的前2個字符表示Android中的不透明度。

的2個十六進制字符的範圍可以從00到FF。對於示例 -

  • 普通不透明的黑色六角形 「#000000」
  • 完全透明的黑色 - 「#00000000」
  • 完全不透明的黑色 - 「#FF000000」
  • 50%透明黑 - 「# 80000000「

這樣,您可以將任何顏色更改爲任何級別的透明度。

源 - http://zaman91.wordpress.com/2010/03/22/android-how-to-create-transparent-or-opeque-background/

2

您可以使用這些

android:background="@android:color/transparent" 
android:listSelector="@android:color/transparent" 
+0

對我很有用。謝謝 – 2013-09-20 07:56:59

0

檢查這個博客。

[http://aboutyusata.blogspot.in/2013/10/how-to-make-listview-with-transparent.html][1]

android:background="@android:color/transparent" 
+0

我已經發布了一個解決方案在這裏:http://stackoverflow.com/questions/16560448/android-transparent-colored-listviews-with-background/38368774#38368774 – user2288580 2016-07-14 08:09:42