我正在尝试为我的应用添加背景图片。我为横向 View 和纵向 View 使用了两张图像。
我经历了this问题的答案,但没有帮助。
这是我的肖像 View 背景。
<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" >
这是我的横向 View 背景。
<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">
当我在纵向 View 中加载我的应用程序时,会显示纵向背景 View ,当我将方向更改为横向时,相同的纵向图像会拉伸(stretch)并显示。但是,当我在横向 View 中加载应用程序时,会显示横向背景 View 。
当我们改变方向时,我应该怎么做才能改变背景图像。
- 编辑 -
list 中的 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)
希望它有用。
关于android背景图片不根据view改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32179356/