Reputation: 1787
I want to make an arc view in my layout , I've tried to use a library but it doesn't works fine , how can I make an arch view like this and attache a button to it for example :
I've tried some codes but they wasn't displaying properly on tablet and different size of screens
Upvotes: 2
Views: 1024
Reputation: 545
If you are developing for API >= 21, then vector path may be a solution.
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="500.0"
android:viewportHeight="500.0"
android:width="50dp"
android:height="50dp">
<path
android:fillColor="@color/colorAccent"
android:pathData="M0 0 H500 V300 H-500"/>
<path
android:fillColor="@color/colorAccent"
android:pathData="M0,300 L500 300, A4,2 0 1,1 0,210 Z"/>
</vector>
What we are doing here is draw two vector paths (maybe possible with one path only, but for demonstration purposes I am going to explain with two paths).
The first path
<path
android:fillColor="@color/colorAccent"
android:pathData="M0 0 H500 V300 H-500 Z"/>
In the first line we setup the color for the shape. Then in the second line actual working starts.
So, we end up drawing a nice rectangle shape (try to comment the second path's code to see that rectangle).
More explanation to come (for path 2)...
Upvotes: 1
Reputation: 2119
Here's a custom solution I've came up with.
It's basically using
For various screens you have to define the height/margin values in values.xml files though, but works fine I guess.
inside of which can be seen like this
Here's the layout file for this.
Not an elegent solution, but someone might benefit from this I think.
Upvotes: 1