问题
Updated
I have a problem with gradient bitmaps on android 2.3. I read this great article and decode my bitmaps using next options:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = true;
And on android 2.2 everything is great, but on android 2.3 gradient artifacts remain even after that decoding.
I run application from article on 2.3 with my bitmaps and all variants are bad: 16/32 bit, (not) dither and RBG_565, ARGB_8888 and ARGB_4444 - gradient has artifacts. Also I tried to decode without options. Everything is ok. Sorry, problem was in
opts.inScaled=true;
opts.inDensity=100;
opts.inTargetDensity=800;
But now I need to make working this code on android 2.3 and its still produce bad gradient (on android 2.2 everything is ok):
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);
I tried to set window pixel format in onCreate
/before/after that method next way:
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(getWindow().getAttributes());
lp.format = PixelFormat.RGBA_8888;
getWindow().setAttributes(lp);
But nothing has been changed (it's gingerbread, it's using 32 bit window format).
Why do so behaviour appear and how can i solve my problem?
Thanks. Good day!
回答1:
solved with moving drawables to hdpi
folder.
来源:https://stackoverflow.com/questions/6746166/gradient-on-gingerbread