Android 背景图片不随视图改变
Android background image does not change according to the view
我正在尝试为我的应用添加背景图片。我使用了两张图片用于横向视图和纵向视图。
我查看了 this 个问题的答案,但没有帮助。
这是我的纵向视图背景。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >
这是我的横向视图背景。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_land">
当我在纵向视图中加载我的应用程序时,会显示纵向背景视图,当我将方向更改为横向时,相同的纵向图像会拉伸并显示。但是,当我在横向视图中加载应用程序时,会显示横向背景视图。
当我们改变方向时,我应该怎么做才能改变背景图像。
- 编辑 -
Activity 来自清单。
<activity
android:name="com.NICT.nict.LoginActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
您可以在布局中指向相同的资源,并将 2 个资源放在可绘制文件夹中。
1- 布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >
2- 可绘制对象
../res/drawable/background (Portrait default mode)
../res/drawable-land/background (Landscape mode)
希望有用。
为了克服这个问题,
在 res
中创建一个 drawable-land
将风景背景图片复制到该文件夹中
从清单中删除 android:configChanges="orientation|screenSize"
现在,背景图片完美加载,没有任何错误。
我正在尝试为我的应用添加背景图片。我使用了两张图片用于横向视图和纵向视图。
我查看了 this 个问题的答案,但没有帮助。
这是我的纵向视图背景。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >
这是我的横向视图背景。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_land">
当我在纵向视图中加载我的应用程序时,会显示纵向背景视图,当我将方向更改为横向时,相同的纵向图像会拉伸并显示。但是,当我在横向视图中加载应用程序时,会显示横向背景视图。
当我们改变方向时,我应该怎么做才能改变背景图像。
- 编辑 -
Activity 来自清单。
<activity
android:name="com.NICT.nict.LoginActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
您可以在布局中指向相同的资源,并将 2 个资源放在可绘制文件夹中。
1- 布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >
2- 可绘制对象
../res/drawable/background (Portrait default mode)
../res/drawable-land/background (Landscape mode)
希望有用。
为了克服这个问题,
在 res
中创建一个 drawable-land
将风景背景图片复制到该文件夹中
从清单中删除 android:configChanges="orientation|screenSize"
现在,背景图片完美加载,没有任何错误。