1

当设备旋转时,我无法在重复平铺模式下保持背景。当我旋转设备时,背景会从重复的图块变为拉伸的图像。

背景是可绘制的 XML (bg.xml)。此 XML 有一个位图,它是一个小的 PNG 文件,平铺模式设置为重复。

<?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/bgimg"
        android:tileMode="repeat" />

现在一个片段膨胀了一个特定的布局。此布局有一个 ScrollView。此 ScrollView 将背景设置为上述 bg.xml 文件。布局文件如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainRoot"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="8dip"
        android:layout_weight="1"
        android:background="@drawable/bg" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            text views
            buttons
            etc

        </LinearLayout>
    </ScrollView>
    </LinearLayout>

如果片段首先以横向或纵向模式显示,则背景图像将按预期平铺。但是,在显示片段的同时旋转设备后,背景图像就会拉伸并且不再平铺。

我有一个活动(不是片段),它在其主要的 LinearLayout (而不是 ScrollView)中使用相同的背景,并且此活动工作正常。

我没有任何代码来处理背景图像,只有 XML 文件。

如果我在 Eclipse 中预览片段,然后旋转,它的行为正常。

布局文件位于“布局”文件夹中。我没有“布局土地”的文件夹。

我测试的设备是带有 Android 2.2 的三星 Galaxy (GT-I9000)(我还没有在其他设备上测试过)。

4

0 回答 0