2017-01-05 38 views
1

我面臨一個惱人的問題幾個小時。Android adjustResize與固定的利潤

我有一個帶有標誌的相對佈局,它有一個marginTop和一個與底部對齊的按鈕,它有一個marginBottom。在這兩種觀點之間還有一些其他的觀點,其中心。

enter image description here

問題鍵盤打開時發生。我想要發生的事情就是解除一切。發生的事情是,按鈕被擡起,徽標保持固定位置,其他視圖被擠壓在中間(在小設備上,它們甚至消失)。

enter image description here

我知道這個問題是可以解決的,如果所有其他視圖將相對於彼此,從徽標或按鈕啓動(不能兩個!)。但在這種情況下,徽標和按鈕將不在所需的位置。

任何想法,不勝感激。

+0

嘗試把它放在其他的東西視圖RelativeLayout的滾動型 –

+0

。它可能會解決您的問題 – Moses

+0

@KoenVanLooveren我已經把它放在一個滾動視圖 – Teodora

回答

0

我想你discribe什麼位置:

不要忘記FILLVIEWPORT =真。爲滾動視圖

這是我想通了,和它的作品完美:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <RelativeLayout 
     android:id="@+id/activity_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context="be.vanlooverenkoen.testing.MainActivity"> 

     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="wrap_content" 
      android:layout_height="150dp" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:scaleType="fitXY" 
      app:srcCompat="@mipmap/ic_launcher" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/button" 
      android:layout_below="@+id/imageView" 
      android:background="@color/colorAccent" /> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:text="Button" /> 
    </RelativeLayout> 
</ScrollView> 
+0

是的,它確實有效,但edittext被擠壓。在我的情況下,因爲我有android:layout_marginTop =「50dp」標識和android:layout_marginBottom =「100dp」按鈕,編輯文本的大小甚至更小(有時甚至消失)。 – Teodora