Search code examples
javaandroidtransparency

android- transparent RelativeLayout


I want to make an activity which has a gradient drawable as background and is going to show 4 panels (RelativeLayout) on top of it's background. now I want to make the 4 panels transparent(e.g. 50%) so that the gradient background could be seen, too. I searched google, but I found only ways to do this with activities not layouts. how to do what I want?


Solution

  • You can create a drawable with shape content. And put your styles in it.

    Sample:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <solid android:color="#77ffffff"/>
    
    </shape>
    

    Create a file with a name such as sampleBackground.xml in the drawable folder in the res path. And set the background attribute of your panels to it:

    android:background="@drawable/sampleBackground"