为什么我的Hello World Android Activity跨越整个屏幕?

问题描述:

更新为什么我的Hello World Android Activity跨越整个屏幕?

添加以下样式,并将其设置为我的申请后,我得到它画整个屏幕:

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

在开发我的第一个Android应用程序,我意识到,我的应用'视图永远不会跨越整个屏幕,而我已下载的其他示例项目也可以。为了测试这一点,我创建了一个基本的活动课程,并将TextView的背景设置为绿色以查看其跨越的程度。原谅我,如果这是一个愚蠢的问题,但我是新来的。

下面是截图:

enter image description here

下面是完整的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, *" 
    android:background="#00FF00" 
    /> 
</LinearLayout> 

这里是e中另一个应用程序的屏幕截图mulator做工精细,跨越整个窗口:

enter image description here

编辑

我编辑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, *" 
    /> 
</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" /> 

仍然是错误的大小。

+2

为您的线性布局设置背景颜色。这样你可以看到它是被截断的TextView还是LinearLayout。 – Gophermofur

+0

@Gophermofur刚从TextView中删除了bg,添加到了LinearLayout中,清理并构建,运行,结果相同:-( –

+0

)您可以发布您的manifest.xml吗? – Gophermofur

它的到来罚款在Android 2.2模拟器

enter image description here

检查清单,看看它是否支持不同的屏幕尺寸。您可以在此质量检查中找到更多信息(fill_parent is not filling entire screen in LinearLayout

显然,如果您没有指定它支持小的,正常的,大的,任意密度的屏幕大小,则可能会出现布局不能填充整个屏幕的问题。

+0

我对这个有很高的期望......但是它没有工作,添加了'support-screens'的代码作为引用,干净+构建,运行,结果相同。 –