具有双色表示的水平单条形图

时间:2013-07-25 10:03:03

标签: android animation svg imageview bar-chart

在Android中使用两种颜色表示创建水平单条形图的最简单方法是什么? 像这样enter image description here

金额64%显然可以及时增加到100%(动画??? :() 是SVG还是图像视图还是如何?

1 个答案:

答案 0 :(得分:0)

此布局达到上述目的,在代码中调整p3 TextView宽度(红色背景)作为p1 TextView宽度(蓝色背景)的百分比将p4 TextView文本更改为当前百分比(考虑到百分比达到100%时要做什么,因为标签会重叠,建议在某个限制之后在p3上设置文本值,比如85%,然后隐藏p4。我建议使用AsyncTask(或其他线程方法),如果逐步增加百分比以查看UI更新。还要看Android Tween Animation。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:orientation="horizontal"
    android:padding="5dp">  
    <TextView
        android:id="@+id/bar"
        android:layout_width="5dp"
        android:layout_height="25dp"
        android:background="#FF000000" />
  <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="5dp">
    <TextView
        android:id="@+id/p1"
        android:layout_width="220dp"
        android:layout_height="wrap_content"
        android:background="#FF00FFFF" />
    <TextView
        android:id="@+id/p2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/p1"
        android:text="100%" />
    <TextView
        android:id="@+id/p3"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:background="#FFFF0000"
        android:gravity="end"  />
    <TextView
        android:id="@+id/p4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/p3"
        android:text="64%" />
  </RelativeLayout>
</LinearLayout>