如何根据TextView的在Android的比例填充图像的颜色 [英] how to fill the color of image according to percentage of textview in android

查看:188
本文介绍了如何根据TextView的在Android的比例填充图像的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据textview.and应根据textview.below的百分比变化的百分比填写的形象是我的code所以请检查。

How to fill the image according to percentage of textview.and it should change according to percentage of textview.below is my code so please check.

              private void displayData(String data) {
    if (data != null) { 
        battery.setText(data);
    }
    }

这是我的TextView我得到的数据是100或约60类似that.what以往任何时候都值我有那么多的水平我的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:layout_toRightOf="@+id/batterylevel"
android:layout_below="@+id/sos"
android:layout_above="@+id/portbearmode"

android:alpha="1"
android:adjustViewBounds="true"

 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"/>

这篇关于如何根据TextView的在Android的比例填充图像的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆