如何在android中制作弧线

时间:2017-11-02 02:03:56

标签: android xml

我只是想知道如何制作这个半圈

enter image description here

但我的输出是这样的

enter image description here

这是我的xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"
 />
<stroke
    android:width="2dip"
    android:color="@android:color/darker_gray"
    />
<padding
    android:left="4dp"
    android:right="4dp"
     />

3 个答案:

答案 0 :(得分:0)

您可以尝试:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval"
       android:useLevel="false" >
   <solid android:color="#006AC5" />
   <size
    android:height="50dp"
    android:width="50dp" />
</shape>

这是一个例子:

enter image description here

我希望它可以帮助你解决问题!

答案 1 :(得分:0)

试试这段代码:

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

在drawable文件夹下创建一个semicircle.xml。
将上面的代码添加到XML中 请告诉我它是否正常工作......

输出看起来像

enter image description here

修改

上面的代码稍作修改。

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

   <size
       android:width="120dp"
       android:height="60dp"/>
   <corners
       android:topLeftRadius="60dp"
       android:topRightRadius="60dp"/>
   <stroke
      android:color="#919191"
      android:width="1dp"
      />

</shape>


输出:
enter image description here

不满意?为什么不使用this在画布上创建它,或使用this将SVG转换为XML代码?

答案 2 :(得分:0)

尝试此代码包含笔划

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#90000000" />
            <size
                android:width="120dp"
                android:height="60dp" />
            <corners
                android:topLeftRadius="60dp"
                android:topRightRadius="60dp" />
        </shape>
    </item>
    <item
        android:bottom="0dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#90DF1E1E" />
            <size
                android:width="120dp"
                android:height="60dp" />
            <corners
                android:topLeftRadius="60dp"
                android:topRightRadius="60dp" />
        </shape>
    </item>
</layer-list>

enter image description here