簡體   English   中英

Android背景圖片不會根據視圖而改變

[英]Android background image does not change according to the 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" >

這是我的風景視圖背景。

<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
        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個資源放置在drawable文件夾中。

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)

希望它能工作。

為了克服這個問題,

  1. 在res內創建可繪制區域

  2. 將風景背景圖像復制到該文件夾​​中

  3. 從清單中刪除android:configChanges =“ orientation | screenSize”

現在,背景圖像可以完美加載而沒有任何錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM