2015-06-06 86 views
0

我有一個非常簡單的佈局,我設計實現了屏幕頂部的工具欄。我在這裏使用權重來適應所有設備。像11一樣給工具欄,89給內容主體。無論如何,這將適合所有屏幕。佈局正在推高

問題

我有內容主體內,並且滾動視圖我有樣4個EditText視圖內滾動視圖。當我點擊最後一個EditText鍵入它時,我的佈局被特別推上了我必須使用重量的工具欄。 現在請不要告訴我不要使用重量,只是告訴我如何解決它。我怎樣才能停止佈局推升?就像Gmail客戶端一樣。當你輸入的時候,標題不會被推上去,在那裏你可以保存或者發送郵件。

enter image description here

main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <RelativeLayout 
      android:id="@+id/header" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:background="#ffe234" 
      android:layout_weight="11" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_centerInParent="true" 
       android:text="Memories" /> 
     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="89" > 

      <ScrollView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <EditText 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:ems="10" /> 

        <EditText 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:ems="10" /> 

        <EditText 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:inputType="textMultiLine" 
         android:minLines="6" 
         android:ems="10" /> 
       </LinearLayout> 
      </ScrollView> 
     </LinearLayout> 
    </LinearLayout> 

</RelativeLayout> 

回答

0

請在您的佈局中使用weight ="0.11"weight ="0.89"
而不是
weight ="11" AMD weight ="89"

+0

還是一樣:-( –

0

在您的清單中,您希望添加編輯或添加android:windowSoftInputMode。然後將其設置爲adjustNothing,如果您不希望屏幕調整。

<activity 
    android:name=".MainActivity" 
    android:label="@string/app_name" 
    android:windowSoftInputMode="adjustPan|adjustNothing"> 
</activity> 

文檔

安卓windowSoftInputMode

http://developer.android.com/guide/topics/manifest/activity-element.html

adjustNothing的0x30不要調整或平移窗口,以騰出空間軟輸入區;該窗口從不調整它。

http://developer.android.com/reference/android/R.attr.html#windowSoftInputMode

+0

有沒有關於'adjustNothing'-flag的任何文檔?從來沒有聽說過它,並且無法在官方網站上找到它 – Ole

+0

@Ole我剛剛發佈了android:windowSoftInputMode的文檔,但是我沒有碰到'adjustNothing'-flag,這很奇怪,因爲它應該在那裏,我會繼續尋找更多的東西,這讓我很好奇。 –

+0

@ Ole剛剛發佈了關於adjustNothing'-flag的文檔。看看它。還有其他一些選項。 –

0

佈局是向上推,因爲滾動視圖調整到整個屏幕時輸入方法出現。

嘗試使用ScrollView的屬性isScrollContainer將其設置爲false。

看起來應該像下面這樣:

... 
    <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:isScrollContainer="false" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:ems="10" /> 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:ems="10" /> 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:inputType="textMultiLine" 
        android:minLines="6" 
        android:ems="10" /> 
      </LinearLayout> 
     </ScrollView> 
... 

如果這沒有幫助考慮在AndroidManifest.xml你的活動設置適當windowSofInputMode

+0

我使用該屬性但仍保持不變plusScroll視圖不是因爲滾動視圖在內容中佔總數的89%。 –

+0

LinearLayout不應該將layout_height設置爲「wrap_content」嗎?它是ScrollView的孩子。將其設置爲「wrap_content」,並讓我知道如果有幫助,請 –