当前位置:编程学习 > wap >>

android显示渐变图片的问题

写了个测试渐变图片显示的demo,关键代码如下:
myView=(ImageView)findViewById(R.id.imgView);
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
if(bitmap!=null){
  myView.setImageBitmap(bitmap);
}

编译时如果设置的sdk level为10-13(对应的android2.3-android3.1),则渐变图片可以正常显示,
如果sdk level为15(对应android4.0),则渐变图片不能正常显示,会有明显的轮廓。


查看了一些资料,说是andoird4.0默认的格式是rgb565,显示24位图片时需要设置下格式
getWindow().setFormat(PixelFormat.RGBA_8888);

不过,设置了之后依然无效。求解!
--------------------编程问答-------------------- getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);


BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.gradient, options);

findViewById(R.id.main).setBackgroundDrawable(new BitmapDrawable(gradient));

试试
--------------------编程问答-------------------- 我的板子上无效,不过在另一款4.0的手机可以正常显示。
不会要通过修改android底层代码才能提供支持吧? --------------------编程问答-------------------- 在你的 activity 中设置 android:hardwareAccelerated="false" 可能会帮上你。




 
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,