Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradient Background that fades in to being Transparent

I am trying to make a bar fade in to the background of my RelativeLayout. Basically start off from back and then fade to being transparent. You get the idea.

Here's the xml I have now:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="@color/black_translucent"
        android:endColor="#323232"
        android:angle="90"
        android:type="linear"
        android:useLevel="true"
        />
</shape>

And the View I applied this to:

 <View
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:background="@drawable/gradient_top" />

The problem: the View has a sharp ending edge at the bottom. I am confused since the gradient ends in transparent. However I still get a shark edge at the bottom of the View. How can I tweak this to get a fading edge?

like image 308
Dinuka Jay Avatar asked Jan 20 '16 05:01

Dinuka Jay


People also ask

What is transparent background in Android apps?

Transparent background is one of the most popular feature for android apps because with the transparent effect android application developer can easily build smooth glass effect android apps or apps that works same as widgets.

What is the opacity of a transparent gradient in Android?

When using @android:color/transparent you need to remember that it represents a completely transparent version of a particular color (opacity set to 0%; A component is equal to #00). You cannot forget this color has its own RGB components which are NOT skipped when calculating gradient values.

How to add background color for text view in Android Studio?

So your background color would be #33FFFF00 Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. In the above code we have give 20% transparent yellow background for text view.

How to change the color of a gradient on Android?

You can customize the colors of the gradient according to your image theme. To do so, tap on the gradient and select the Colors icon to choose the colors you wish to apply. You can go with the Document Colors to add the best-suited colors for your gradient. 4. Adjust the Transparency The last step is to adjust the transparency of the gradient.


1 Answers

Neither of your colours are transparent.

@color/black_translucent suggests that it's translucent, not transparent.

You could use @android:color/transparent instead.

like image 94
alex Avatar answered Nov 11 '22 12:11

alex