【问题标题】:gradient on Gingerbread姜饼上的渐变
【发布时间】:2011-07-19 11:06:43
【问题描述】:

更新
我对 android 2.3 上的渐变位图有疑问。我读了这个great article 并使用下一个选项解码我的位图:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = true;
在 android 2.2 上一切都很好,但在 android 2.3 上,即使在解码之后,渐变伪影仍然存在。

我用我的位图在 2.3 上运行 application from article,所有变体都是 坏的:16/32 位、(不是)抖动和 RBG_565、ARGB_8888 和 ARGB_4444 - 渐变有伪影。我也尝试在没有选项的情况下进行解码。 一切正常。抱歉,问题出在

opts.inScaled=true;
opts.inDensity=100;
opts.inTargetDensity=800;

但是现在我需要在 android 2.3 上运行这段代码,它仍然会产生不好的渐变(在 android 2.2 上一切正常):

    ImageView imageView = (ImageView) tabView.findViewById(R.id.tabsImage);
    // decode bitmaps
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    options.inDither = true;
    Bitmap tabImageOn = BitmapFactory.decodeResource(mainActivity.getResources(), tabImageResourceOnId, options);
    Bitmap tabImageOff = BitmapFactory.decodeResource(mainActivity.getResources(), tabImageResourceOffId, options);
    // create new selector
    StateListDrawable tabImage = new StateListDrawable();
    tabImage.addState(new int[] { android.R.attr.state_selected }, new BitmapDrawable(mainActivity.getResources(), tabImageOn));
    tabImage.addState(new int[] {}, new BitmapDrawable(mainActivity.getResources(), tabImageOff));
    tabImage.setDither(true);
    // set selector to tab
    imageView.setImageDrawable(tabImage);
我尝试在onCreate/before/after 中设置窗口像素格式:
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(getWindow().getAttributes());
    lp.format = PixelFormat.RGBA_8888;
    getWindow().setAttributes(lp);

但什么都没有改变(它是姜饼,它使用 32 位窗口格式)。

为什么会出现这种行为,我该如何解决我的问题?

谢谢。美好的一天!

【问题讨论】:

    标签: android gradient android-2.3-gingerbread


    【解决方案1】:

    解决了将drawables移动到hdpi文件夹的问题。

    【讨论】:

      猜你喜欢
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多