我正在使用RangeSeekBar为3个条件设置一些值(例如,绿色=确定,琥珀色=警告,红色=撤离)...我正在使用xml drawable设置像这样的背景
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#27F70C"
android:centerColor="#FFBF00"
android:endColor="#FC0505"
android:angle="0" />
<corners android:radius="0px" />
<stroke
android:width="2dp"
android:color="#70555555" />
<stroke
android:width="0dp"
android:color="#70555555" />
</shape>
这样的结果
现在,我想根据搜索栏值更改背景色,以便如果更改范围,则应更改背景色,例如:
我知道我可以通过编程方式更改渐变,但是如何缩小起始颜色并增加最终颜色?有人对此有解决方案吗?
谢谢
尝试View
在下方创建三个RangeSeekBar
,并在移动滑块时更新每个宽度。
大致来说,这可能像:
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<View
android:id="@+id/green"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#00FF00"/>
<View
android:id="@+id/orange"
android:layout_toRightOf="@id/green"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#FFFF00"/>
<View
android:id="@+id/red"
android:layout_toRightOf="@id/orange"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#FF0000"/>
<RangeSeekBar android:layout_width="300dp" android:layout_height="wrap_content">
</RelativeLayout>
在此示例中,您将更新三个颜色视图的宽度,以便在移动滑块时它们的总和为300dp。
您可以为三个视图的背景使用纯色(看起来像第二张图像),也可以创建三个渐变(绿色到绿黄色,黄橙色,橙红色)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句