2012-11-20 42 views
2

我有「磚」,各自有以下作爲其android:background財產的一個GridView:Android的 - 梯度怪誕

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <gradient 
     android:endColor="#00FFFFFF" 
     android:gradientRadius="180" 
     android:startColor="#55FFFFFF" 
     android:type="radial" /> 

</shape> 

當滾動網格最初呈現,瓷磚看起來是這樣的:

enter image description here

列表中向下滾動之後,甚至只是一個單一的像素,所有的磚然後讓這種新的,像素化尋找梯度:

enter image description here

梯度是在一個相對佈局,定義爲這樣的(其具有在其內部對星,一個TextView等的ImageView的):

<RelativeLayout 
    android:id="@+id/tile_image_layout_gradient" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/radialbg" 
    android:orientation="vertical" 
    android:paddingBottom="10dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:paddingTop="20dp" /> 

的特定的電話,這是打破是一款Experia,運行Android 2.3.4。 Galaxy S3似乎很好,但任何基於4.x的x86仿真器也有與僞像相同的問題。

回答

6

請嘗試setContentView()前將onCreate()方法設置此,:

getWindow().setFormat(PixelFormat.RGBA_8888); 

您也想MAYBE需要編程設置背景在這種情況下,不通過XML。

+0

像素格式並沒有解決它,當你會建議試圖以編程方式設置BG? – Josh

+1

實際上,當我從onAttach移動到創建 – Josh

+1

時,確實奏效。 :-) –

2

將以下覆蓋添加到您的活動中,這應該通過將窗口格式設置爲支持更多顏色來解決您所看到的色帶問題。

@Override 
public void onAttachedToWindow() { 
    getWindow().setFormat(PixelFormat.RGBA_8888); 
} 

更多信息:http://developer.android.com/reference/android/view/Window.html#setFormat(int)

+0

不幸的是,這並沒有奏效。 – Josh

+2

我把它移到了蚊子建議的onCreate上,它工作。非常感謝! – Josh