Android: Custom Drawable in a SeekBar widget is drawing aliased images(Android:SeekBar 小部件中的自定义 Drawable 正在绘制别名图像)
问题描述
问题是当我在 SeekBar 小部件中使用自定义 progressDrawable(可能不正确)时,它会以非常混叠/丑陋/低质量的形式呈现.我已将drawingCacheQuality"设置为高,没有区别.有人有什么想法吗?
Problem is when I am using a custom progressDrawable in a SeekBar widget (perhaps incorrectly) it is rendered in a very aliased/ugly/low quality form. I have set "drawingCacheQuality" to high and there is no difference. Anyone have any ideas?
我在 Nexus One (OS 2.2.1) 上开发,目标构建为 API 1.5(尽管我希望这不重要).
Am developing on a Nexus One (OS 2.2.1) with target build for project as API 1.5 (though I would hope that shouldn't matter).
这是它的外观示例:
我的目标是创建一个具有两种状态(开和关)的简单漂亮的视觉开关,以及在它们之间移动的滑块.我真的没有看到更好的小部件,而且几乎所有的事情都是用 SeekBar 为我完成的.如果有人有一个更好的主意,不涉及重写大量的样板代码,那就太好了.看起来这真的应该以最小的努力以某种方式使用或扩展 SeekBar 是可行的.不过我有点不知所措.
My aim is to create a simple nifty visual switch with two states (on and off), and a slider to move between them. I didn't really see a better widget for this and practically everything is done for me with SeekBar. If someone has a better idea which doesn't involve rewriting tons of boiler plate code that would be nice. It just seems like this should really be doable with minimal effort somehow working with or extending SeekBar. I'm at a bit of a loss where to start though.
我猜一个想法是将我的 on_off 图像叠加到 ShapeDrawable 上并将其用作背景(以及用于 progressDrawable 的@android:color/transparent"),但我不太熟悉如何这样做...
I'm guessing one idea would be to just overlay my on_off image onto the ShapeDrawable and use that as the background (and "@android:color/transparent" for progressDrawable), but I'm not too familiar with how to do that...
新活动的基本代码
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
seek = (SeekBar)findViewById(R.id.seek);
seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
if (seek.getProgress() < seek.getMax() / 2.0)
seek.setProgress(0);
else
seek.setProgress(seek.getMax());
}
});
}
定义 SeekBar 的 main.xml
main.xml defining the SeekBar
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<SeekBar android:id="@+id/seek"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content" android:layout_width="200dip"
android:background="@drawable/background"
android:padding="4dip"
android:drawingCacheQuality="high"
android:progressDrawable="@drawable/slider_on_off"
android:progress="99" android:max="99"
android:maxHeight="100dip"
android:thumb="@drawable/slider_box"
android:thumbOffset="0dip"
/>
</RelativeLayout>
background.xml seekbar 的背景
background.xml Background of seekbar
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:useLevel="false" >
<corners
android:radius="4dip" />
<solid
android:color="#FF282828" />
</shape>
推荐答案
绘图缓存质量与您要执行的操作无关.确保将图像放在 res/drawable-hdpi 文件夹中.
The drawing cache quality has no relation with what you are trying to do. Make sure that you put your images in the res/drawable-hdpi folder.
这篇关于Android:SeekBar 小部件中的自定义 Drawable 正在绘制别名图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android:SeekBar 小部件中的自定义 Drawable 正在绘制别名图像
基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 降序排序:Java Map 2022-01-01