2014-05-09 24 views
3

我正在Android中執行消息傳遞屏幕。佈局是LinearLayout。adjustResize和軟鍵盤開啓時保留EditText比例

Messaging Screen

但當鍵盤可見。

Keyboard visible

佈局的在底部的比例就會混亂。我如何強制它保持其比例?這是我的佈局文件。我嘗試adjustPan,editText是可見的,但行動欄已經消失。我想使用adjustResize,因爲我也想操作欄,但editText不再可見。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:flatui="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:background="@color/background_grey" 
     android:layout_weight="93" > 

     <ListView android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <TextView android:id="@android:id/empty" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:textAppearance="@android:style/TextAppearance.Large" 
      android:text="No chat history." /> 

    </LinearLayout> 

    <LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_margin="5dp" 
     android:layout_weight="7"> 

     <com.cengalabs.flatui.views.FlatEditText 
      android:id="@+id/message" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" 
      android:gravity="top" 
      android:hint="Message" 
      android:layout_marginRight="5dp" 
      flatui:theme="Deep" 
      flatui:fieldStyle="transparentBox" 
      flatui:cornerRadius="3dip"/> 

     <com.cengalabs.flatui.views.FlatButton 
      android:id="@+id/sign_in_button" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:text="Send" 
      android:layout_weight="1" 
      flatui:theme="Deep" 
      flatui:textAppearance="none"/> 

    </LinearLayout> 

</LinearLayout> 
+0

你可以在你的清單文件寫???? –

+0

@BornToWin我添加到activity標籤的唯一的東西是'android:windowSoftInputMode =「stateHidden | adjustResize」' – Boy

回答

2

嘗試使用此佈局:

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


    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/background_grey" 
     android:layout_above="@+id/bottomToolbox"> 

     <ListView android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <TextView android:id="@android:id/empty" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:textAppearance="@android:style/TextAppearance.Large" 
      android:text="No chat history." /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/bottomToolbox" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_margin="5dp"> 

     <com.cengalabs.flatui.views.FlatEditText 
      android:id="@+id/message" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" 
      android:gravity="top" 
      android:hint="Message" 
      android:layout_marginRight="5dp" 
      flatui:theme="Deep" 
      flatui:fieldStyle="transparentBox" 
      flatui:cornerRadius="3dip"/> 

     <com.cengalabs.flatui.views.FlatButton 
      android:id="@+id/sign_in_button" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:text="Send" 
      android:layout_weight="1" 
      flatui:theme="Deep" 
      flatui:textAppearance="none"/> 

    </LinearLayout> 

</RelativeLayout> 
+0

這個答案就是我一直在尋找的!謝謝。 – Boy