如何在 Android 中创建一个底部切割的半椭圆形按钮?

问题描述

我正在尝试创建一个半椭圆形按钮,这在模型中很容易,但我发现在 XML 文件中很难做到。此外,我希望涟漪效应仅限于椭圆形。 可能有一种我不知道的在形状 XML 文件中切割椭圆的方法

我正在努力实现的目标:

bottom half oval button

但我得到的最接近的是:

What i got so far

使用以下代码

   public void participate(Video v,Participation cp) {
        Gson gson = new Gson();
        String json = gson.toJson(v);
        String json2 = gson.toJson(cp);
        String url = Statics.BASE_URL + "/api/competition/participate/?video=" + json + "&participation=" + json2;

        con.setUrl(url);

        con.addResponseListener(new ActionListener<NetworkEvent>() {
            @Override
            public void actionPerformed(NetworkEvent evt) {
                String str = new String(con.getResponseData());
                System.out.println(str);
                Dialog.show("Confirmation","Your Video has been successfully added","Ok",null);
                con.removeResponseListener(this);
            }

        });
        NetworkManager.getInstance().addToQueueAndWait(con);

任何建议将不胜感激。我看到的所有选项都没有达到预期的效果

解决方法

试试下面的代码

<?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>

查看以下资源

Half circle shape not work

希望对您有所帮助!