Android Shape - Gradient should go to the right side - android

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!
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.

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.

Related

How to have multi-layered kind of shadow/gradient in Android

I am trying to achieve this layout. The upper part is a bit dark and it decreases as we move down making it complete transparent. I tried a couple of gradient variations but didn't get the desired results. Does anybody have idea of how to achieve this. Is it gradient or shadow ?
Create a gradient file and use this code you can increase or decrease transparency as you want
layout-->new file-->layout resource file--> give any name
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient android:startColor="#B71A1A1A"
android:angle="270"
android:centerColor="#00FFFFFF"
android:endColor="#00FFFFFF"/>
</shape>
</item>
</selector>

Add border around an image view selectively

I have an image view on my Android UI. While I can add a border around it using a style, I need to be able to add a border selectively (so that it is only on the top and bottom or left and bottom or any other permutation from 1 to all 4 sides).
I've googled around to try and find a solution and most say go the style route (which I don't think will work in this instance).
Is there a way to add a border selectively around an UI element on android?
You can try this following code
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="-3dp"
android:insetRight="-2dp">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#android:color/black" />
</shape>
</inset>
It will remove the left and right border of any view.

Android Radial Gradient does not work properly

I'm working on an Android application in Xamarin. For button backgrounds, I've created a simple XML. The code is:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient android:startColor="#ff000000"
android:centerColor="#ffffffff"
android:endColor="#00ffffff"
android:type="radial"
android:gradientRadius="100"
/>
</shape>
</item>
</selector>
When I use linear or sweep in android:type code, everything is fine. A good transparent gradient appear in my device (My device is HTC One M8). But when I use radial, a bad solid color appears, no transparency. I want to use this technique for the shadow under buttons, but if you check the screenshot below, a very bad harshy solid color appear under the buttons.
If the code uses RGB or ARGB color, it draws a buggy solid gradient!
Is it a bug in the code, in my device or in the Xamarin deploy setting?

Relative layout gradient mask android

Hi i'm now developing application that contain a profile like twitter profile
I got a small problem .
the problem is how to make a gradient black trasparent mask effect like this
can anyone help me or provide me a code how to make this effect with xml please
thank's :)
If I good understood you you should create new drawable xml as below:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="#000000"
android:centerColor="#C0C0C0"
android:endColor="#FFFFFF"
android:angle="90"/>
</shape>
And set it as background on your view.

How to create a rectangle shape with 2 sides in android

I want to show edit text box with two sides. so, for that i need to create a rectangle shape with two sides. PLease help some one.
create a drawable under drawable folder and add the belwow contents (border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#color/black" />
<stroke android:width="1dip" android:color="#color/white"/>
</shape>
Now set the Background of the EditText to this draw able like :
android:background="#drawable/border"
I think the best way to do this is to create a 9-patch in PhotoShop with required border sides... there are also several other ways... depends on your design.

Categories

Resources