Android全屏布局位置

发布于 2024-12-23 18:24:04 字数 2520 浏览 1 评论 0原文

我在将操作设置为全屏时遇到问题。当我将操作设置为全屏时,布局向下移动,它不会从屏幕的上边缘绘制。但当我按下菜单按钮并显示菜单时,它会自行修复。

我通过以下代码将其设置为全屏: setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

我还使壁纸可见并隐藏标题栏。它在 android 2.1 和 2.2 上进行了测试

简化代码:

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 :

<?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

<?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

更新:

我发现如果我将 EditText 替换为 TextView,它就可以正常工作。如果 EditText 是第一个显示的 View,则布局将向下移动。

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);

I also make the wallpaper can be visible and hide title bar. It was tested on android 2.1 and 2.2

simplified Code:

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 :

<?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

<?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:

Result

Update:

I found that if I replace the EditText to TextView, it works properly. If the EditText is the first View to show, the layout will be shifted down.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄与心 2024-12-30 18:24:04

我猜这是因为你在设置后执行了 super.onCreate 。请尝试以下操作:

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);
    }
}

I guess it's because you execute super.onCreate after your settings. 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);
    }
}
梦幻的心爱 2024-12-30 18:24:04

尝试:

requestWindowFeature(FEATURE_NO_TITLE);

requestWindowFeature 必须在调用之前调用在 Activity 的 onCreate 中设置 setContentView(view)。还可以拨打以下电话:

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

Try:

requestWindowFeature(FEATURE_NO_TITLE);

requestWindowFeature must be called before you call setContentView(view) in your Activity's onCreate. Also call the following:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文