Android 如何正确应用RGBA_8888和抖动?
我有splash.png和渐变。但在屏幕上这张图片看起来不太好 我对这个问题的简单回答包括:Android 如何正确应用RGBA_8888和抖动?,android,Android,我有splash.png和渐变。但在屏幕上这张图片看起来不太好 我对这个问题的简单回答包括: public class TestditherActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override
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>
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"/>
看看这个:
或者这篇关于Android中抖动的博文:
在您的例子中,问题在于位图xml。我记得在某个地方读到,抖动只有在位图设置了tileMode时才起作用。我修改了代码,在emulator中,结果是完美的,但在Galaxy S上仍然不太好。可能是在将.apk编译到设备上时,图像质量较低。或者设备屏幕不支持那么多像素。如果将galaxy s与Android 2.1配合使用,抖动将无法正常工作(请参阅本文:)我将galaxy s与Android 2.3.7版配合使用
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));
}
}
<?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"/>