<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 背景图 -->
<item android:id="@android:id/background"
android:drawable="@drawable/back" />
<!-- 进和能量图 -->
<item android:id="@android:id/progress"
android:drawable="@drawable/fill" />
</layer-list>我在seekbar中定义了前景图和背景图。seekbar现在能按我的要求显示前景和背景。我现在的问题是如何估代码中动态的替换前景图和背景图。假如图片比较多。如果10张前景,10张背景就要做10*10个xml。这个现实中比较麻烦。
解决方案 »
- 请问,大家开发android是在windows下呢?还是在linux下?
- 求一个安卓的中文api帮助文档。。英文不好是硬伤啊。。。
- 定制android应用程序-有偿
- android2.2 视频通话图象质量问题
- android 读写权限问题
- 求梦幻诛仙2传承服邀请码一个
- Android google map 开发 ,求帮助!!!!!!
- 大侠们我想问两个Android开发使用jsoup解析html的相关问题
- webView打开的页面和手机浏览器打开的不一样
- ava.lang.SecurityException: Given caller package is not running in process
- 发送一条短信,如何判断接收房是否已经收到短信了
- 最近在跟一个老师做一个项目,关于安卓安全方面的。求助大神们我该怎么去学习安卓的安全构架方面的知识?
Resources res = getResources();
LayerDrawable progressDrawable = (LayerDrawable) res.getDrawable(R.drawable.seekbar_progress);
progressDrawable.setDrawableByLayerId(android.R.id.background, res.getDrawable(R.drawable.back));
ClipDrawable proDrawable = new ClipDrawable( res.getDrawable(R.drawable.fill1), Gravity.LEFT,ClipDrawable.HORIZONTAL);
progressDrawable.setDrawableByLayerId(android.R.id.progress,proDrawable); seekBar1.setProgressDrawable(progressDrawable);
长大见识了。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/seekbar_background"
android:dither="true"
/>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient
android:startColor="#80028ac8"
android:centerColor="#80127fb1"
android:centerY="0.75"
android:endColor="#a004638f"
android:angle="270"
/>
</shape>
</clip>
</item>
<item
android:id="@android:id/progress"
android:drawable="@drawable/seekbar_progress_bg"
/>
</layer-list>
SeekBar
<SeekBar
android:id="@+id/frequency_slider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="20"
android:progress="0"
android:secondaryProgress="0"
android:progressDrawable="@drawable/seekbar_progress"
android:thumb="@drawable/seek_thumb"
/>Programmatically
// ------------ custom seekbar
LayerDrawable layer = (LayerDrawable) verticalSeekBar_1.getProgressDrawable();Drawable draw1 = (Drawable)layer.findDrawableByLayerId(android.R.id.progress);
Bitmap bitmap1 = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.scroll_on);draw1 = new ClipDrawable(new BitmapDrawable(bitmap1), Gravity.AXIS_PULL_BEFORE, ClipDrawable.HORIZONTAL);layer.setDrawableByLayerId(android.R.id.progress, draw1);Drawable draw2 = (Drawable) layer.findDrawableByLayerId(android.R.id.background);Bitmap bitmap2 = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.scroll_off);draw2 = new BitmapDrawable(bitmap2);
layer.setDrawableByLayerId(android.R.id.background, draw2);你也可以参考:http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/