Android layerlist is not working in different mobiles - java

I want to create a drawable file like the below screenshot.
My drawable xml file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="0px"
android:left="0px"
android:right="0px"
android:bottom="0px">
<shape android:shape="rectangle">
<corners android:radius="#dimen/_6sdp" />
<solid android:color="#color/activeslots"/>
</shape>
</item>
<item
android:top="#dimen/_14sdp"
android:left="#dimen/_12sdp"
android:right="#dimen/_58sdp"
android:bottom="#dimen/_14sdp">
<shape android:shape="oval">
<solid android:color="#color/white"/>
<size android:height="#dimen/_20sdp"
android:width="#dimen/_20sdp"/>
</shape>
</item>
</layer-list>
I created rectangle and oval inside the layer_list. But the issue is it is not working in different mobiles, also the white circle inside the drawable is becomes big after setting height and width.

Related

divide a ring drawable into two equal part in android

i want to have a half drawable ring just like an arc.
i have a code that just creates the ring but i am confused how to make it a half ring.
how do i achieve this half ring drawable?
<shape android:shape="ring"
android:innerRadius="15dp"
android:thickness="20dp"
android:useLevel="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/blue"/>
<size android:height="200dp" android:width="200dp"/>
</shape>
This is the image that exactly looks like what am trying to achieve.
click here
you can create like this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:end="0dp"
android:left="-500dp">
<shape>
<corners android:radius="500dp" />
<solid android:color="#color/colorPrimary" />
</shape>
</item>
<item
android:end="100dp"
android:bottom="100dp"
android:top="100dp"
android:start="-400dp">
<shape>
<corners android:radius="500dp" />
<solid android:color="#color/white" />
</shape>
</item>
</layer-list>
if you went to perfect view then create svg file for this

How to get this ellipse shape in android seekbar?

I'm trying to do a custom circular seekbar but i haven't being able to achieve this shape yet.
The problem is basically that long circle shape because i did a custom circular seekbar before:
This is the code from the second picture:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="ring"
android:thicknessRatio="16"
android:useLevel="false">
<solid android:color="#color/black" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:shape="ring"
android:thicknessRatio="16"
android:useLevel="true">
<solid android:color="#color/green" />
</shape>
</rotate>
</item>
</layer-list>
I've tried changing the size but it obviously give it a different form:
Does anyone have any clue for me to get this?

How do I draw this round rectangle?

enter image description hereI am a beginer in Android doing an internship and i have been given the task to complete this navigation drawer for the app.Any help would be highly appreciated
Create new drawable and add the following code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:topLeftRadius="20dp" android:bottomRightRadius="20dp"/>
<solid android:color="#color/semi_transparent_white"/>
</shape>
</item>
</selector>

how do you make buttons flash or blink different colours in android eclipse?

I am creating a tic tac toe program. I can get the buttons to display an X or 0 but I can't get them to display different colours. How would I do this?
Use a selector to change button color when clicked.
/res/drawable/btn_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid android:color="#ffaa66"/>
</shape>
</item>
<item>
<shape>
<solid android:color="#ffdd99"/>
</shape>
</item>
</selector>
And now apply this xml as android:background to the button.

Best way to tint my buttons?

I'm currently developing an android app where I use transparent png's as buttons for the user interface.
The buttons look kinda like this:
When the user presses the button I want to automatically tint the non-transparent pixels in the image to a darker color.
Currently I use an xml selector with different drawables for each state. This obviously doesn't scale well since I need to make several versions of each image in photoshop.
Any solutions? I heard that you can use the setColorFilter method on ImageView's to achieve this, but a full explanation would be great!
Thanks!
set this image as source to ImageButton and set ImageButton's state (backgriund) using xml state list, something like this
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape
>
<gradient
android:startColor="#android:color/background_light"
android:endColor="#android:color/darker_gray"
android:angle="90"/>
<stroke
android:width="1dp"
android:color="#999999" />
<corners
android:radius="9dp"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient
android:endColor="#android:color/transparent"
android:startColor="#android:color/transparent"
android:angle="270"/>
<stroke
android:width="1dp"
android:color="#989797" />
<corners
android:radius="9dp"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#android:color/transparent"
android:startColor="#android:color/transparent"
android:angle="90"/>
<stroke
android:width="1dp"
android:color="#999999" />
<corners
android:radius="9dp"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"/>
</shape>
</item>
</selector>

Categories