使用drawable中的xml在Android中创建像弧形一样的弯曲线

时间:2016-06-28 09:55:39

标签: android xml android-drawable shapedrawable

我做了什么 ..

<item>
    <rotate
        android:fromDegrees="40"
        android:toDegrees="20"
        android:pivotX="25%"
        android:pivotY="50%" >
        <shape
            android:shape="line"
            android:top="1dip" >
            <stroke
                android:width="1dip"
                android:color="#FF0000" />
        </shape>
    </rotate>
</item>

旋转但不弯曲。它需要弯曲以形成弧形状

任何想法?

1 个答案:

答案 0 :(得分:2)

您可以绘制ring形状,根据您的偏好轮换它,并使用ProgressBar作为progressDrawable并设置进度。

drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="150"
    android:toDegrees="150">

    <shape
        android:shape="ring"
        android:thickness="10dp"
        android:innerRadius="20dp"
        android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 -->

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

    </shape>
</rotate>

layout.xml

<ProgressBar
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:progressDrawable="@drawable/widget_arc"
    android:indeterminate="false"
    android:max="100"
    android:progress="67"
    />

您可以通过动态设置进度并轻松设置动画

*使用维度值