android button with half circle edges

微笑、不失礼 提交于 2020-01-02 03:06:48

问题


I am trying to create a shape to be used for my imagebuttons in my Android project that would essentially have half circles for the left and right sides.

I thought I could just use a shape XML with a radius, but that just rounds the corners where I need the whole left and right sides to be half circles like the image below.

My current XML for the shape looks like this:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" 
    android:color="@color/white">

    <corners
       android:radius="60dip"
         />

    <stroke
        android:width="0dp"
        android:color="#000000" />


     <solid
        android:color="@color/white" />

</shape>

but I am trying to get this effect :


回答1:


How tall is your button? The shape drawable with rounded corners should work, you want the radius to be half of the height of the button.




回答2:


You must specify every corner radius 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="@color/green" />
    <size android:height="30dp" />
    <corners
        android:bottomRightRadius="15dp"
        android:bottomLeftRadius="15dp"
        android:topRightRadius="15dp"
        android:topLeftRadius="15dp"
        />
</shape>

You should not specify the width, so that it can adjust the width as background drawable.



来源:https://stackoverflow.com/questions/20954590/android-button-with-half-circle-edges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!