Android背景没有填充屏幕

时间:2012-05-28 06:09:14

标签: android background-image

我有一个带有tabHost的应用程序;在其中一个标签上我有一个背景图像,但图像没有填满整个屏幕:

bgnd image

我的图片是480 x 800 px

我的home.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/home_bgnd">
</LinearLayout>

如何修复此代码,以便我的图像覆盖整个屏幕?

2 个答案:

答案 0 :(得分:1)

在XML中使用ImageView并设置android:scaleType="fitXY"以使其延伸到其父布局。作为父级布局,我建议您使用FrameLayout,以便图像可以作为它的背景。

例如:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:src="@drawable/your_source"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <!-- your other views here -->

    </LinearLayout>
</FrameLayout>

答案 1 :(得分:1)

在这种情况下,您似乎正在使用tabhost,您必须查看您拥有tabhost的xml布局。

检查包含android:id="@android:id/tabcontent"的视图中的填充,并从那里删除该填充或边距。

相关问题