如何根据百分比改变圆的颜色

时间:2015-10-10 06:05:15

标签: android

我想显示圆圈中湿度的百分比。并根据湿度百分比动态改变圆圈的颜色。 我创建了以下layout.Created两个drawable与两种不同的颜色。enter image description here

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/registration_bg"
    >

    <RelativeLayout
        android:id="@+id/image_layout"
        android:layout_width="@dimen/circleheight"
        android:layout_height="@dimen/circleheight"
        android:background="@drawable/circle1"
        android:layout_below="@+id/linearlayout"
        android:layout_centerInParent="true"
        >
        <Button
            android:id="@+id/image_level"
            android:layout_width="@dimen/circleheight"
            android:layout_height="@dimen/circleheight"
            android:background="@drawable/circle2"
            android:layout_centerInParent="true"
            />
</RelativeLayout>
</RelativeLayout>

这是我的mai布局文件

以下是两个可绘制文件

circle1.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <gradient android:startColor="@color/circle1"
        android:endColor="@color/circle1"
        android:angle="270"/>
</shape>

circle2.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <gradient android:startColor="@color/circle2"
        android:endColor="@color/circle2"
        android:angle="270"/>
</shape>

0 个答案:

没有答案