I started customizing circular widget on my android application. i got something similar to my requirements by converting recycler view into a curved shape. but the problem is multiple layers are overlapping each other. how to make layers independently clickable. please help me out. Thanks in advance.
look at this This is how recycler views are overlapping each other
the expected design looks like this
Use this in your drawable file. it will be make right curve.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/colorPrimary" />
<corners android:topRightRadius="150dp" />
</shape>
Related
I’d like to achieve the following look in my app to try and group the views into a more logical layout.
I was thinking of creating a Shape Drawable for the rectangle something along the lines of this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="12px"/>
<stroke android:width="2dip" android:color="#000000"/>
</shape>
But what I’m not sure about how to place the rectangle in the view. Most of the examples I’ve seen are placing a drawable as a background for a single view, not multiple views as per the above.
Do I need to create some sort of ‘blank’ view which holds no purpose but to house the rectangle? How would I go about this?
Everything is currently defined in a constraint layout.
Create a layout around the views and set its background as the drawable you created.
You will have to add this as a background to the Viewgroup where all these views are.
For eg. add this drawable as background to the relative layout.
Thanks for the comments all. Thought I'd update this with what I implemented as although the other answers were correct, I still didn't quite grasp what was required, so here's some additional information:
Create a file called 'rectangle.xml' in the drawable folder, with the following content:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="12px"/>
</shape>
Then in the layout file in which I wanted to place the rectangle, I added the following view. The key bit that I didn't understand was how to specify the size/position of the rectangle. This was achieved by defining the following constraints to wrap it around the items I wanted.
<View
android:id="#+id/myRectangleView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="#id/unit_spinner"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="#id/time_label"
android:background="#drawable/rectangle"
android:elevation="2dp"
/>
Couple of other points I struggled with:
Even though I defined this view before all the views it surrounds,
the arrows on the spinners were displaying behind the rectangle. To fix this, I had to use the elevation property on the view, and set all the other views to be higher.
I struggled to get the position of
the rectangle where I wanted it using the margin/padding of the
rectangle view, so instead had to add padding to the views it was
surrounding. Not sure if this is the right approach - I'm still
toying with it.
I am struck at this problem of creating the UI in android. I need a xml-based solution to this problem. I don't want to use any SVG or PNG image to achieve the solution. Is there any way to achieve this of view in android.
You should be using a <layer-list> element of xml to draw such a UI.
Following code will be used to create oval shape:
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#AAAAAA"></solid>
<size android:height="100dp"
android:width="60dp">
</size>
This leads to the following shape:
Once you know how to draw an oval shape using xml. Now next step for you is to learn how to use <layer-list> to achieve desired output. To learn using <layer-list> you can follow this tutorial.
By creating a new drawable file which will describe the look of the widget you want to draw,more or less.You can then set it as background for which widget you want to change the original look of. I would recommend starting with rectangle if you want to achieve the shape shown in your question. the drawable file will look something like this:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#000"/>
<corners android:radius="150dp"/> <!-- The value here should specify How much ovally you want shape be -->
</shape>
and then assigning the background of the widget to this drawable should do the trick, something like this:
<LinearLayout
android:background="#drawable/oval">
Hope this was helpful :D
So, I need to create three different buttons which look almost the same: all of them have rounded corners but different background colors. What I did is to have three different shapes created and give them a particular color. Although this approach gets the job done, I think there's gotta be a better and less cumbersome way to do this.
I've found a workaround to this by changing the background dynamically, but I was wondering whether there's an easier way to have this done without having to write any Java code.
This is the code for all three of the drawables:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="4dp"/>
<padding
android:bottom="15dp"
android:top="15dp"
android:left="15dp"
android:right="15dp" />
<solid
android:color="#color/green" />
</shape>
Is there any way to use "some kind of inheritance" to extend the code above to have three different "children" of this shape by only adding / overriding some of the parent's properties?
Thanks in advance!
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.
i design my app in photoshop and i create most of my design but i cant create this shape:
but i only can create rectangle with code below
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="80dp" android:height="30dp" />
<solid
android:color="#color/blue"/>
</shape>
anyone can help me?
thanks for yr reply
Do you absolutely need it to be an android shape? Or could you simply use a png?
Check this out on how to make a custom button: http://developer.android.com/guide/topics/ui/controls/button.html
Or for the most flexibility add an imageview:
http://developer.android.com/reference/android/widget/ImageView.html
And then set an ontouch listener to it:
How to implement touch listener on image?
Hope this helps.