简体   繁体   English

Android:SeekBar小部件中的Custom Drawable正在绘制别名图像

[英]Android: Custom Drawable in a SeekBar widget is drawing aliased images

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. 问题是,当我在SeekBar小部件中使用自定义progressDrawable时(可能不正确),它以非常别名/难看/低质量的形式呈现。 I have set "drawingCacheQuality" to high and there is no difference. 我将“ drawingCacheQuality”设置为高,没有区别。 Anyone have any ideas? 有人有想法么?

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). 我正在Nexus One(OS 2.2.1)上进行开发,其目标版本为API 1.5(尽管我希望这没关系)。

Here is a sample of what it looks like: 以下是其外观示例:

替代文字

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. 我并没有真正看到一个更好的小部件,而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. 看起来这确实应该是可行的,并且只需花费很少的精力就可以使用或扩展SeekBar。 I'm at a bit of a loss where to start though. 我从哪里开始有点茫然。

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... 我猜测一个想法是将我的on_off图像叠加到ShapeDrawable上,并使用它作为背景(对于progressDrawable,则使用“ @android:color / transparent”),但是我对如何做到这一点不太熟悉。 ..

Basic code for a new actvitiy 新活动的基本代码

    @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());
            }
        });
    }

main.xml defining the SeekBar main.xml定义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 Background of seekbar background.xml 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>

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. 确保将图像放在res / drawable-hdpi文件夹中。

Well, the post its pretty old but there's a way to do it with togglebuttons. 好吧,该帖子已经很老了,但是有一种方法可以通过切换按钮来实现。

Its VERY WELL described in this page: http://www.mokasocial.com/2011/07/sexily-styled-toggle-buttons-for-android/ 此页面描述得很好: http//www.mokasocial.com/2011/07/sexily-styled-toggle-buttons-for-android/

If anyone is trying to do something like that, take a look there. 如果有人试图做这样的事情,那就去那里看看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM