ARGB在Android应用中无法正常运行

时间:2011-06-30 18:42:08

标签: android

在我的ListView中按下时,我正在尝试将透明背景应用于我的行。我像这样创建文件list_selector.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/argb80804040" />
</selector> 

在我的news_item.xml中,我定义了如下背景:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/list_selector">

<ImageView
   android:id = "@+id/img"
   android:layout_width="95dip"
   android:layout_height="75dip"
   android:layout_alignParentLeft = "true"
   android:paddingTop="10dip"
   android:layout_marginLeft="10dip"
   android:paddingBottom="10dip"
   android:src="@drawable/no_news_image_small" />     

<TextView android:id="@+id/title"
    android:layout_gravity="center_vertical"
    android:layout_width="fill_parent"
    android:layout_weight="1.0"
    android:layout_height="wrap_content" 
    android:textSize="12sp" 
    android:textStyle="bold"
    android:paddingTop="5dip"
    android:layout_marginLeft="110dip"
    android:textColor="#21B6EF"
    android:singleLine="true" />

<TextView android:layout_gravity="center_vertical"
    android:layout_width="fill_parent"
    android:layout_weight="1.0"
    android:layout_height="wrap_content" 
    android:layout_marginLeft="110dip" 
    android:textSize="10sp" 
    android:id="@+id/description" 
    android:layout_below="@id/title"
    android:paddingBottom="10dip" 
    android:layout_marginBottom="5dip" 
    android:textColor="#fff"/>

</RelativeLayout>

但是,它显示为纯色而不是ARGB颜色。我的drawable定义如下:

<resources>
    <item type="drawable" name="transparent_orange">#64ff7b00</item>
    <item type="drawable" name="argb80804040">#80804040</item>
    <item type="drawable" name="argb40000000">#40000000</item>
    <item type="drawable" name="argb80408040">#80408040</item>
</resources>

我是否需要做其他事情以使aplha颜色有效?我正在尝试使用我自己的设备(motorola defy),我也在使用另一个使用相同alpha颜色的应用程序,并且颜色在此应用程序中显示正常,但在我的设备中,它并非如此。

非常感谢您的回应 Ť

1 个答案:

答案 0 :(得分:0)

我真的不明白你想要实现什么,但我的建议将是

在res / values / colors.xml中定义颜色

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="transparent_orange">#64ff7b00</color>
  ...
</resources>

然后你可以在res / drawable / test.xml中定义一个drawable用作这样的背景:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <solid android:color="@color/transparent_orange" />
</shape>

最后,您可以使用生成的drawable作为目标容器的属性

android:background="@drawable/blue_linear_gradient"