【问题标题】:How to create this particular shape with xml in Android?如何在 Android 中使用 xml 创建这个特定的形状?
【发布时间】:2016-07-20 11:51:58
【问题描述】:

我想创建一个形状,如下图所示,但我想用 XML 代码(可绘制)创建这个,我不想 创建这个9.patch图片!

如何使用 xml 代码创建此形状?

【问题讨论】:

    标签: android android-xml android-shape


    【解决方案1】:

    这是一个解决方法

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" android:padding="10dp">
        <solid android:color="#FFFFFF"/>
        <corners 
        android:bottomRightRadius="0dp"
        android:bottomLeftRadius="0dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp"/>
    </shape>
    

    调整拐角半径以使您的上半部分弯曲!

    或重叠这个椭圆形以获得所需的输出

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
        <!--circle filling color-->
        <solid android:color="#ffffff" />
        <stroke
        <!--radious can define in here-->
        android:width="1dp"
        android:color="#ffffff" />
        <corners
        android:bottomLeftRadius="2dp"
        android:bottomRightRadius="2dp"
        android:topLeftRadius="2dp"
        android:topRightRadius="2dp" />
    </shape>
    

    但基本上,这不是正确的方法!换一种方式,使用 9 补丁

    【讨论】:

    • 谢谢伙计,但这个形状不只是围绕顶部半径!你的代码就在拐角处!
    • 调整一下兄弟,我没有打开,所以无法真正为您提供确切的输出!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多