Android-transparent RelativeLayout

I want to do an operation that has a gradient that can be selected as a background, and will show 4 panels (RelativeLayout) on top of the background. now I want 4 panels to be transparent (e.g. 50%) so that you can see the gradient background. I searched google, but I only found ways to do this with actions, not layouts. how to do what i want?

+4
source share
4 answers

You can create drawable with shape content. And add your styles to it.

Example:

 <?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, for example, sampleBackground.xml in a folder with the ability to transfer in the res path. And set the background attribute of your panels to it:

 android:background="@drawable/sampleBackground" 
+12
source

You can use the alpha attribute for your layout if you want to make it transparent. It can be used as follows: -

 <RelativeLayout android:id="@+id/yourRelativeLayoutID" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:alpha="0.7" android:gravity="bottom"> </RelativeLayout> 

set the alpha value from 0.1 to 1.0. It depends on the level of transparency you want.

Hope this helps. :)

+9
source

You can use this:

 <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" > </RelativeLayout> 
+3
source

I managed to get a transparent background in RelativeLayout elements by specifying a background color:

 <RelativeLayout android:layout_height="match_parent" android:layout_width="wrap_content" android:background="@color/modal_background" > </RelativeLayout> 

And in my colors.xml I created a color called modal_background with an alpha value. This specific example is black ( #000000 ) with an alpha value of CC :

 <resources> <item name="modal_background" type="color">#CC000000</item> </resources> 
+1
source

Source: https://habr.com/ru/post/1499090/


All Articles