Android drawable behind a bitmap - android

I am trying to achieve this crazy thing but I not sure if this is possible using Android drawable.
I have an image which as some transparent parts, then I am trying to have another gradient sweep element behind this Image to rotate so that the transparent parts of image get moving gradient color.
As of now, I am able to get Image and an gradient sweep behind it but it is not rotating and effect is not as I expected. Any suggestion/tips/code snippets will be helpful.
Here is my drawable XML.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<shape
android:innerRadiusRatio="15"
android:shape="ring"
android:thicknessRatio="4"
android:useLevel="false">
<gradient
android:angle="0"
android:endColor="#color/colorAccent"
android:startColor="#android:color/white"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
</item>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/inoffline" />
</item>
</layer-list>
and the output image, I have swapped the transparent parts of image so that i could easily verify that both drawable are rendered.
Regards,
Harsha

Related

how to get the color code from Gradient in android ProgressBar

I have created the ring shaped curved gradient for the progress bar, to make it curved from the edge i have created the ring shaped dot item in layer-list and set one at the starting of the progress and the other one at the bottom. The issue here is gradient color effect is dynamic so i have to change the bottom dot color to same as gradient bottom color, is there a way to get the gradient bottom color code dynamically ? Attached image is the exact layout i'm trying to implement.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/gradientDrawable">
<rotate
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.67"
android:shape="ring"
android:thickness="#dimen/_6sdp"
android:thicknessRatio="40.0">
<gradient
android:centerColor="#E85E44"
android:endColor="#FF9C00"
android:startColor="#FF9C00"
android:type="sweep" />
</shape>
</rotate>
</item>
<item android:id="#+id/topDot" android:bottom="#dimen/_126sdp">
<shape
android:innerRadiusRatio="5000"
android:shape="ring"
android:thickness="#dimen/_3sdp"
android:useLevel="false">
<solid android:color="#FF9C00" />
</shape>
</item>
<item android:id="#+id/bottomDot">
<rotate>
<inset android:insetBottom="#dimen/_126sdp">
<shape
android:innerRadiusRatio="5000"
android:shape="ring"
android:thickness="#dimen/_3sdp"
android:useLevel="false">
<solid android:color="#E85E44" />
</shape>
</inset>
</rotate>
</item>
</layer-list>

How to create geometric shape for all of the screen sizes?

I want to create geometric shape for all of the screen sizes in Android.
I wrote the code for this case. But my shape changes in other screen sizes.
I want to create shape like the following picture
And my code is:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate android:fromDegrees="0">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimaryDark" />
</shape>
</rotate>
</item>
<item android:top="180dp" android:bottom="-100dp" android:left="-70dp" android:right="-50dp">
<rotate android:fromDegrees="6">
<shape android:shape="rectangle">
<solid android:color="#color/base_color6" />
</shape>
</rotate>
</item>
</layer-list>
I did this but it breaks on different resolution. Because of the angle view are distort and that causes major UI issue. To break that, I create a WEBP Image with that angle and set it to the background. And set the whole view around that in ConstraintLayout with group and barrier. Now it pretty much work fine on various resolution device

How to draw complicated shape in android, with contain of triangle, rectangle and stroke

I have a task to create chat. Here is the UI:
I've tried to draw rectangle and triangle and in layer list to combine this 2 drawables, but it looks very bad...
Rectangle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="50dp"/>
<solid android:color="#color/message_cloud_client" />
<stroke android:color="#color/message_cloud_client_stroke" android:width="1dp"/>
</shape>
Triangle.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="90%" >
<shape
android:shape="rectangle" >
<stroke android:color="#android:color/transparent" android:width="10dp"/>
<solid
android:color="#dce7f7" />
</shape>
</rotate>
</item>
</layer-list>
You can do this using Nine-patch images instead of creating a layer-list. In a `Nine-patch' image you can indicate the rectangle that is grown or shrink when the image is resized. But the whole image is not affected. Here is the address of the tool:
sdk\tools\draw9patch
Open the file. Import your original image and set a rectangle inside the original images that is affected when the image is resized. (Do not include the edges of your picture).
Also you can do this with Vector images that is now available in support library.

Creating a semi border of circle with textview

I want some thing like this image. The blue color on the border of the circle is custom and should increase/decrease as per the value in text view. I would like to have some ideas to implement it.
Please try with the below code
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
android:toDegrees="360">
<shape android:shape="ring" android:innerRadiusRatio="3"
android:thicknessRatio="10" android:useLevel="false">
<size android:width="100dip" android:height="100dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#4ab0da"
android:endColor="#4ab0da"
android:centerColor="#eee"
android:angle="0"
/>
</shape>
</rotate>
Please visit this Circle Progress Indicator official blog
Features
Increase or decrease progress changes
Modifiable
Ring width
Ring background color
Ring fill color
Ring gradient

Creating triangle shape xml without wasting space android

The solutions I have found over internet cuts the rectangle but I am having like half of it without nothing and wasting space.
For example:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<stroke android:color="#android:color/transparent" android:width="10dp"/>
<solid
android:color="#color/black" />
</shape>
</rotate>
</item>
</layer-list>
This code creates a triangle, but I have a lot of space wasted, look at the image:
I want to create a triangle that "fills" the image view. Something like this:
Not necessarily has to be equilateral. Any ideas?
Well, if it is okay for you to create the shape in java , you can do it by extending the Drawable class in Android. See this

Categories

Resources