Android 1.5 transparent view bug

E-mail Print PDF

Nominally, you can make Android View or Layout transparent or semi-transparent by changing the android:background color definition in the layout XML. However, this doesn’t work quite as you might expect on Android 1.5.

For example, attempting to create a layout which includes an image as a background with a semi-transparent overlay like this:


<!-- Use a relative layout with background image, with a semi-transparent overlay in an enclosed LinearLayout -->


<RelativeLayout android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/default_bg">


<LinearLayout android:id="@+id/LinearLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#99FFFFFF"
>
.....
</LinearLayout>
</RelativeLayout>

On Android 1.5, you will end up with a view with a white background. On Android 1.6, you (correctly) have the background image with a semi-transparent white overlay. I guess that is why the Android example code for translucent background uses a transparent PNG rather than setting the alpha in the background colour - there is a bug in 1.5 which prevents it working!