繁体   English   中英

为什么我的Hello World Android Activity不在整个屏幕上?

[英]Why isn't my Hello World Android Activity spanning the entire screen?

更新

添加以下样式并将其设置为我的应用程序后,我已经绘制了整个屏幕:

<resources>
    <style name="app_theme" parent="android:Theme.NoTitleBar">
        <item name="android:windowBackground">@color/green</item>
    </style>    
</resources> 

在开发我的第一个Android应用程序时,我意识到我的应用程序的视图从不跨越整个屏幕,而我已经下载的其他示例项目。 为了测试这个,我创建了一个基本的活动类,并将TextView的背景设置为绿色,以查看它的跨越程度。 请原谅我这是一个愚蠢的问题,但我是新手。

这是截图:

在此输入图像描述

这是完整的HomeActivity来源:

public class HomeActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

这是布局文件( /res/layout/main.xml ):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text="Hello World, StackOverflow"
    android:background="#00FF00"
    />
</LinearLayout>

这是模拟器中另一个应用程序的截图,工作正常,跨越整个窗口:

在此输入图像描述

编辑

我现在编辑了我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#00FF00"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text="Hello World, StackOverflow"
    />
</LinearLayout>

然后清理和构建,运行并获得相同的视图。

编辑2

我按要求删除了“垂直”方向线,没有变化。

这是我的AndroidManifest:

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

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <application android:label="@string/app_name" >
        <activity android:name="HomeActivity"
                  android:label="@string/app_name">
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

<application>下的清单中添加了以下内容

<supports-screens android:resizeable="true"
                      android:smallScreens="true" 
                      android:normalScreens="true" 
                      android:largeScreens="true"

                      android:anyDensity="true" />

仍然是错误的大小。

它在Android 2.2模拟器上很好用

在此输入图像描述

检查您的清单,看它是否支持不同的屏幕尺寸。 您可以在此QA中找到更多信息( fill_parent未填充LinearLayout中的整个屏幕

显然,如果您没有指定它支持小尺寸,普通尺寸,大尺寸,任何密度的屏幕尺寸,则可能会出现布局未填满整个屏幕的问题。

暂无
暂无

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

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