我想显示圆圈中湿度的百分比。并根据湿度百分比动态改变圆圈的颜色。 我创建了以下layout.Created两个drawable与两种不同的颜色。
<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>