如何根据值缩放图像的颜色 [英] how to scale the image color according to value
问题描述
如何根据的TextView
的百分比填充图像。并应根据。在下面的code的高度布局的TextView
的比例正在变化更改,但我希望图像的颜色应按照百分比变化(价值的TextView(电池))。
How to fill the image according to percentage of TextView
. and it should change according to percentage of TextView
.in the following code the height layout is changing but i want the color of image should change according to percentage(value of textview(battery)).
code:
private void displayData(String data) {
if (data != null) {
battery.setText(data);
int x=Integer.parseInt(battery.getText().toString());
image_level.getLayoutParams().height = x;
}
}
这是我作为100 的TextView
我得到的数据还是有些像60有史以来that.what i值有那么多的水平我的的ImageView
应填充颜色和显示。
This is my TextView
i am getting data as 100 or some 60 like that.what ever value i got that much level my ImageView
should fill with color and display.
<TextView android:id="@+id/batterylevel"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:text="BRV Battery"
android:layout_below="@+id/sos"/>
<ImageView
android:id="@+id/image_level"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/app_name"/>
在布局我不喜欢这样,我应该适用于任何动画或简单地设置任何选项,请告诉我。
如果电池的TextView
60应填写蓝色高达60和剩余的40为白色。
in the layout i did like this i should apply any animations or simply setting any options please tell me.
if battery TextView
is 60 it should fill blue color upto 60 and remaining 40 as white color.
推荐答案
下面我的方法来获取电量百分比和传递价值的映像级别按钮显示的水平。
the following my method to get the battery percentage and pass that value to imagelevel button to display level.
private void displayData(String data) {
Log.v("______________________No serives_______________",data );
if (data != null) {
battery.setText(data);
int x=Integer.parseInt(battery.getText().toString());
image_level.getLayoutParams().height = x*2;
Log.v("______BATERY LEVEL_________", "__IN DISPLAYDATA()___DCA__________"+data);
}
和以下code是在布局中显示。
and the following code is in layout to display.
<RelativeLayout
android:id="@+id/image_layout"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@+id/linearlayout"
android:background="@drawable/ic_launcher"
>
<Button
android:id="@+id/image_level"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="#8099FFFF"
android:contentDescription="@string/app_name"/>
这篇关于如何根据值缩放图像的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!