android 如何自定义ProgressBar
原文:http://blog.sina.com.cn/s/blog_74c22b210100thpv.html
1. 在res/values/colors.xml中定义ProgressBar要用的图片颜色
<?xml version="1.0" encoding="utf-8"?><resources>????????<!--定义图片颜色--><drawable name="transparent_background">#00000000</drawable><drawable name="white">#ffffff</drawable></resources>
????????<!--定义文字颜色--><color?name="solid_red">#f00</color><color name="solid_blue">#0000ff</color>
<item android:id="@android:id/background"???????android:drawable="@drawable/transparent_background" /></layer-list>
<item android:id="@android:id/progress"><clip><shape>???<gradient android:startColor="#FFFFD980"?android:centerColor="#FFFF8C00" ????????android:endColor="#FF6611"?android:angle="270" android:centerY="0.75"?/></shape></clip></item>
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ProgressBar android:layout_width="fill_parent"?????android:layout_height="148dp" android:id="@+id/my_profile_tracker"?????android:background="@null"??????android:progressDrawable="@drawable/progress_bar_layer"?????android:paddingLeft="23dp" android:paddingRight="23dp"?????android:paddingTop="107dp" android:paddingBottom="27dp"?????style="?android:attr/progressBarStyleHorizontal"?????android:indeterminateOnly="false" android:max="60" /><ImageView android:id="@+id/my_profile_tracker_mask"?</RelativeLayout>android:layout_width="fill_parent"android:layout_height="148dp"?android:src="@drawable/profile_screen_tracker" />
super.onCreate(savedInstanceState);setContentView(R.layout.main);ProgressBar?mTracker = (ProgressBar) findViewById(R.id.my_profile_tracker);mTracker.setProgress(20);}
The default level is 0, which is fully clipped so the image is not visible. When the level is 10,000, the image is not clipped and completely visible.