android背景图片不根据view改变

标签 android xml tags

我正在尝试为我的应用添加背景图片。我为横向 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/

相关文章:

java - Android - 构建 list 中出现神秘权限

java - Kotlin Cast EditText、TextView 来查看

HTML:时间格式中的字母 T - 有什么用?

php - 如何捕获属于不同步骤/数组/位置的两个标签之间的多行正则表达式

android - 在多行中并排显示博客样式标签 (Android)

android - 无法更改 ListFragment 项目的文本颜色

javascript - React Native - 将函数的返回值设置为组件的属性不起作用

javascript - 获取 "XMLHttpRequest is not defined"

java - 我想使用 xpath 读取 xml 并获取 java 中父级的计数

c# - 如果对象元素根标记不存在,如何将 XML 反序列化为对象?