我一直在尋找一段時間,並沒有爲我的問題找到任何解決方案,所以我決定在這裏問你們。可能解決辦法很簡單,我太盲目了,看不到它。Android:Immersive Sticky模式在屏幕的左側和右側創建邊距
我正在爲android創建一個小遊戲,其中我必須在位圖上繪製一些行。我想在全屏模式下使用應用程序(沒有狀態欄和沒有導航欄)。所以我使用「Immersive Sticky Mode」,它隱藏了那些酒吧。
我的問題是,我總是在顯示器的左側和右側留出一點餘量,這是我無法使用的。我做了一些截圖,以說明問題。 (我把屏幕截圖粘貼在黑色背景上,所以你可以看到屏幕的邊緣)。
下面是截圖鏈接:http://www.directupload.net/file/d/4091/tgnoufx5_jpg.htm
在該活動中,人們可以在顯示屏上繪製的任意直線(這是沒有意義的問題,但它有助於解釋)。 正如你所看到的,如果我畫線到屏幕的頂部或底部,它會被正確繪製。如果我在右邊或左邊畫一條線,顯示是「有限的」,並且我得到邊緣,線不能繪製。
下面是我使用的代碼:
活動的-XML-代碼:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" />
位對應的Java代碼:
public class DrawActivity extends Activity implements View.OnTouchListener {
private ImageView drawContainer;
private Bitmap bitmap;
private Canvas canvas;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
toggleHideyBar(2);
setContentView(R.layout.activity_drawtrack);
drawContainer = (ImageView) this.findViewById(R.id.imageView1);
drawContainer.setOnTouchListener(this);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
drawContainer.setImageBitmap(bitmap);
}
public void toggleHideyBar(int ch) {
int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
int newUiOptions = uiOptions;
if (Build.VERSION.SDK_INT >= 14) {
newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
if (Build.VERSION.SDK_INT >= 16) {
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if (Build.VERSION.SDK_INT >= 18 && ch == 1) {
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE;
}
if (Build.VERSION.SDK_INT >= 18 && ch == 2) {
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}
編輯:我可以顯示簡單textView-Fields在這些邊緣,所以也許問題是由位圖或Activity-XML(佈局)造成的?仍然沒有弄清楚...