简体   繁体   English

Android全屏布局位置

[英]Android full screen layout position

I got a problem with setting an action to full screen. 将操作设置为全屏时出现问题。 When I set an action to full screen, the layout was shifted down, it does not draw from the top edge of screen. 当我将动作设置为全屏时,布局向下移动,它不会从屏幕的上边缘绘制。 But it will be fix by itself when I press menu button and the menu shown. 但是当我按下菜单按钮和显示的菜单时,它将自行修复。

I set it to full screen by following code: setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); 我通过以下代码将其设置为全屏: setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

I also make the wallpaper can be visible and hide title bar. 我也让壁纸可见并隐藏标题栏。 It was tested on android 2.1 and 2.2 它在Android 2.1和2.2上测试过

simplified Code: 简化代码:

TestActivity.java : TestActivity.java:

package com.test.fullscreen;
import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;

public class TestActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
       setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
       getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);

       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
    }
}

main.xml : main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <EditText
        android:id="@+id/inputBox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#66303030"
        android:cursorVisible="true"
        android:hint="Text"
        android:paddingLeft="7dp"
        android:paddingRight="17dp"
        android:textColor="#ffffff"
        android:textSize="24dp" />

</LinearLayout>

AndroidManifest.xml AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.fullscreen"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".TestActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Result: 结果:

结果

Update: 更新:

I found that if I replace the EditText to TextView , it works properly. 我发现如果我将EditText替换为TextView ,它可以正常工作。 If the EditText is the first View to show, the layout will be shifted down. 如果EditText是第一个要显示的View ,则布局将向下移动。

I guess it's because you execute super.onCreate after your settings. 我想这是因为你在设置后执行super.onCreate。 Try the following: 请尝试以下方法:

public class TestActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       requestWindowFeature(Window.FEATURE_NO_TITLE);

       setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
       getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);

       setContentView(R.layout.main);
    }
}

Try: 尝试:

requestWindowFeature(FEATURE_NO_TITLE);

requestWindowFeature must be called before you call setContentView(view) in your Activity's onCreate . 在Activity的onCreate调用setContentView(view)之前,必须先调用requestWindowFeature Also call the following: 还请致电以下人员:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM