我为android界面制作了一个xml文件。在这个xml中,有一个消耗品。我想用tansparency(alpha)为这个xml添加背景但是当我在相对布局中添加bacground时使用alpha这样的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:alpha="0.2"
tools:context=".ListGestureActivity" >
会使背景透明度变为黑色而不是白色。在其他xml发生的那样。 但在其他xml我尝试这样做
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".HintGestureActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:alpha="0.3"
android:background="@drawable/background"
/>
它奏效了。但是在带有消耗品的xml中没有用。 你有什么建议吗?
答案 0 :(得分:0)
你可以做这样的事情
android:background="#00564678"
对于Ex:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:alpha="0.3"
android:background="#00564678"
/>
答案 1 :(得分:0)
默认情况下,它采用黑色作为背景颜色,之后,如果应用透明度,则无法获得所需的输出。因此,首先需要设置一些背景颜色,然后应用alpha
。试试这个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:alpha="0.2"
tools:context=".ListGestureActivity" >