3
我有splash.png漸變。但是屏幕上看到此圖像看起來不那麼好......如何正確應用RGBA_8888和抖動?
我簡單的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"/>
我已經改變了我的代碼,並在模擬器中的結果是完美的,但在Galaxy S上它仍然不是很好。 – Sviatoslav 2011-12-19 16:14:17
這可能是當您將.apk編譯到設備時,您會得到較低質量的圖像。或者設備屏幕不支持那麼多像素。如果您在Android 2.1上使用星系s,抖動無法正常工作(請參閱此文章:http://www.displaymate.com/Galaxy_S_ShootOut.htm) – Jave 2011-12-19 16:21:15
我使用Galaxy S與Android 2.3.7版 – Sviatoslav 2011-12-19 16:37:01