我有splash.png渐变。但是在屏幕上这个图像看起来不太好......
此问题的简单 .apk 包括:
public class TestditherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
getWindow().setFormat(PixelFormat.RGBA_8888);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/test"/>
</LinearLayout>
和 test.xml :
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/splash"
android:antialias="true"
android:dither="true" />
splash.png
结果
如何正确应用 RGBA_8888 和抖动?我的错误在哪里?
下一个代码在模拟器中给出了完美的结果,但在真实设备上没有:
public class TestditherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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.splash, options);
findViewById(R.id.linear).setBackgroundDrawable(new BitmapDrawable(gradient));
}
}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
答案 0 :(得分:1)
看看这个:
Awful background image quality in Android
或者这篇关于Android中抖动的博文:http://android.amberfog.com/?p=247
在您的情况下,问题出在位图xml中。我记得在某个地方读过,只有当位图设置了tileMode时,抖动才有效。