2010-11-02 31 views
0

我是新來的Android平臺,我正在開發一個應用程序,主要活動 正在使用對話框主題。我的漸變不顯示在我的Android項目中

我的UI設置非常符合我的需要,但漸變似乎不適合我。 我試過一個漸變標題欄,視圖,佈局,textView等,並在每種情況下梯度不顯示。 (到目前爲止,我只在模擬器上測試過它)。

我繪製的XML看起來是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient 
     android:startColor="#00000000" 
     android:centerColor="#FFFFFFFF" 
     android:endColor="#00000000" 
     android:angle="90" /> 
</shape> 

我用下面的設置背景幾個元素,但它永遠不會顯示出來:

android:background="@drawable/gradient_bg" 

我已經嘗試不同的顏色和角度等等,但無濟於事。

如果我做了以下工作,但我更喜歡在XML中做到這一點。

GradientDrawable grad = new GradientDrawable(
     Orientation.TOP_BOTTOM, 
     new int[] {Color.RED, Color.YELLOW} 
    ); 
    this.getWindow().setBackgroundDrawable(grad); 

任何人都可以幫忙嗎? 謝謝。

回答

0

嘗試在整個漸變上設置不透明的顏色。

例如,對於黑色使用#FF000000。兩個第一個十六進制數字是阿爾法值。

0

你的代碼是:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient 
     android:startColor="#00000000" 
     android:centerColor="#FFFFFFFF" 
     android:endColor="#00000000" 
     android:angle="90" /> 
</shape> 

那是工作的罰款,並在Android的HTC Hero手機正確dispaying gredient!它可能是一種情況,可能不會在模擬器上顯示gredient效果。

0

謝謝。我確定它在實際設備上工作,所以它必須是一個模擬器問題。

相關問題