2017-03-17 88 views
1

我爲我的應用程序工作背景,但是當我打開鍵盤時圖像調整大小。相關佈局背景在鍵盤打開時調整大小

我從adjustPan等聽到過,但它並沒有工作。 getWindow.setBackground也不能工作,因爲我在一個片段。

如果我設置了Windows背景它可以工作,但是當我回去時背景仍然存在。
屏幕:
Correct screen
Incorrect screen

+0

添加ImageView的嘗試此解決方案[鏈接](http://stackoverflow.com/a/4737265/3395978) – Marlen

+0

你有一個例子,因爲我didn't瞭解它是如何工作的:C – flectiondev

+0

在FrameLayout中包裝你的視圖,設置你的背景並調整你添加到FrameLayout的內容。 – Marlen

回答

0

的原因似乎是,你使用android:windowSoftInputMode="adjustResize"軟鍵盤打開時調整大小您的活動。這就是你想要的,但是背景圖像總是調整大小以適應整個元素。不要使用背景,請在佈局的底部放置一個ImageView,並將圖像放在正確的android:scaleType處,這樣可以防止縱橫比丟失。

0

scaleType="fitStart"

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="280dp" 
      android:layout_height="match_parent" 
      android:background="@android:color/white" 
      android:paddingTop="8dp"> 

    <ImageView 
     android:id="@+id/img_background" 
     android:src="@drawable/background" 
     android:scaleType="fitStart" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 


    <include layout="@layout/content"/> 

</FrameLayout>