仅在视图(1/4)部分设置背景颜色(Android)

时间:2012-01-19 06:39:07

标签: android textview android-view

是否可以在Android中仅为(1/4)部分设置背景颜色?我有一个用例,我需要选择一个视图并将其分成几部分后对其进行着色,我看过开发人员文档,但我无法找到相同的方法。

编辑:我需要把它变成“| | | |”之类的东西我需要动态地完成它。

3 个答案:

答案 0 :(得分:7)

它对你很有用

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
 <gradient
    android:startColor="#FFFFFF"
    android:endColor="#00000000"
    android:angle="45"/>    
</shape>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/gradient"  >   
</LinearLayout>

答案 1 :(得分:0)

你尝试过使用

吗?
 android:drawableTop="@drawable/....."

答案 2 :(得分:0)

试试这个

<LinearLayout
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_weight="1">
  <TextView
      android:text="red"
      android:gravity="center_horizontal"
      android:background="#aa0000"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:layout_weight="1"/>
  <TextView
      android:text="green"
      android:gravity="center_horizontal"
      android:background="#00aa00"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:layout_weight="1"/>
  <TextView
      android:text="blue"
      android:gravity="center_horizontal"
      android:background="#0000aa"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:layout_weight="1"/>
  <TextView
      android:text="yellow"
      android:gravity="center_horizontal"
      android:background="#aaaa00"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:layout_weight="1"/>
 </LinearLayout>