简体   繁体   中英

Android make part of activity transparent

I have the following layout:

<RelativeLayout>
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" />

    <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="200dip"
      android:layout_alignParentBottom="true" >
    </LinearLayout>
</RelativeLayout>

I want to make the linear layout completely transparent, meaning, the content from the previous activity on the activity stack should be visible in the linear layout region.

I have tried using setAlpha(0) with the linear layout; it does make it transparent, but it shows the activity background color in linear layout region.

I have also tried setting the android:theme for the activity to @android:style/Theme.Translucent.NoTitleBar, but this will make the whole activity show the content of the previous activity.

Can anyone suggest a way?

Thanks.

Just to be clear, Activities are not visible objects. Views are what you see on the screen -- in particular you see the view attached to your activity. In this case that view is the RelativeLayout and its contents.

When you make the LinearLayout transparent, it shows the background color of the RelativeLayout. If you want to see what is behind the relative layout make its background color transparent, too.

<RelativeLayout android:backgrond="#00000000"> 
       ... 
      <LinearLayout android::background="#00000000"> 
           ... 
      </LinearLayout>
 </RelativeLayout>

Of course you probably want to use a named color resource rather than "#00000000"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM