Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Shape - Gradient should go to the right side

What I try to do


I'm trying to create a Backgroud-Shape for my App. For This I created a gradient witch starts in the middle, but I want that it starts on the right side. You can imagine you this like the gradient comes in from the right side.

Question


What do I need to change in my Shape or Gradient that this works?

Code


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">



    <gradient android:gravity="right" android:type="radial" android:gradientRadius="280"
        android:startColor="#FFFFFF" android:endColor="#CBCBCB" /><!--   #e0dede" -->
</shape>

Image


This how it looks at the moment!

enter image description here

Like you see the gradient is in the middle, I want that exactly this gradient starts from the right side into the middle of the screen.

like image 956
safari Avatar asked Jan 20 '26 13:01

safari


1 Answers

Try this and see the magic:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <gradient android:layout_gravity="right" android:type="radial" android:gradientRadius="280"
        android:centerX="100%" android:centerY="50%"
        android:startColor="#FFFFFF" android:endColor="#CBCBCB" /><!--   #e0dede" -->
</shape>

Tags android:centerX and android:centerY lets you start your gradient from any point on your screen.You just need to give related % values as i did here.It worked like magic for me!

I didn't change other tags settings of your code but you will have to change the radius as per how much white portion you need to make visible.

Hope,It helped.

like image 178
Hiral Vadodaria Avatar answered Jan 23 '26 03:01

Hiral Vadodaria