简体   繁体   中英

How do I create a bottom cut half oval shaped button in Android?

I'm trying to create a half oval shaped button, which was easy in the mockup but I found it to be quite difficult doing in the XML file. Also I would like the ripple effect to be constrained only to the oval. There may be a way to cut an oval in the shape XML file that I am not aware of.

What I'm trying to achieve:

下半椭圆按钮

But the closest I got is:

到目前为止我得到了什么

Using the following code:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#8C9AEE"/>
    <size
        android:width="120dp"
        android:height="60dp"/>
    <corners
        android:topLeftRadius="140dp"
        android:topRightRadius="140dp"/>
</shape>

Any advice would be appreciated. Non of the options I saw achieved the desired result.

Try the following code

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#8C9AEE" />
    <size
        android:width="120dp"
        android:height="60dp" />

</shape>

or

see the following resource

Half circle shape not work

Hope you helpful!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM