2014-09-23 125 views
3

我一個已在其中我有兩個buttons.Now我想要的是,當被顯示在兩個按鈕,其在底部的鍵盤應顯示在鍵盤上方及不隱藏一個登記表以上在鍵盤下。爲了達到這個目標,我寫的代碼並沒有給我任何成功。顯示按鈕鍵盤

Xml代碼

<LinearLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical"> 

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

     <LinearLayout 
      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:inputType="textPersonName" 
        style="@style/EditText" 
        android:hint="@string/firstname" 
        android:id="@+id/et_first_name" /> 


       <EditText 
        android:inputType="textPersonName" 
        style="@style/EditText" 
        android:hint="@string/lastname" 
        android:id="@+id/et_last_name" /> 

       <Button 
        style="@style/EditText" 
        android:text="@string/country" 
        android:id="@+id/bt_country" /> 


       <Button 
        style="@style/EditText" 
        android:text="@string/gender" 
        android:id="@+id/bt_gender" /> 

       <EditText 
        style="@style/EditText" 
        android:inputType="phone" 
        android:hint="@string/mobileno" 
        android:id="@+id/et_mobile_no" /> 

       <EditText 
        style="@style/EditText" 
        android:inputType="textEmailAddress" 
        android:hint="@string/email" 
        android:id="@+id/et_email" /> 


      </LinearLayout> 


     </LinearLayout> 
    </ScrollView> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <Button 
      style="@style/EditText" 
      android:id="@+id/bt_reg_cancel" 
      android:text="@string/cancel" 
      android:layout_gravity="bottom" 
      android:layout_weight="1" /> 

     <Button 
      style="@style/EditText" 
      android:text="@string/save" 
      android:id="@+id/bt_reg_save" 
      android:layout_gravity="bottom" 
      android:layout_weight="1" /> 
    </LinearLayout> 


</LinearLayout> 

請你幫助

+0

爲什麼不使用滾動視圖? – Umair 2014-09-23 06:46:03

+0

把裏面的滾動型的按鈕,並嘗試...... – 2014-09-23 06:46:39

+0

我想保持的按鈕位置固定 – user3917131 2014-09-23 06:50:17

回答

1

在Android清單,給物業android:windowSoftInputMode="adjustResize"。這將在鍵盤顯示時調整您的佈局。

所以,如果事情是在底部,它會顯示在鍵盤上方,一旦它表明

「請ü可以告訴我相對佈局的代碼,這將是非常有益的??? - user3917131 7分鐘前「

解決方案: -

  1. )要麼把你的底佈局滾動視圖本身。然後,即使顯示鍵盤,您也可以滾動它。

2)重量的方法: - 滾動型 - > 0.7 的RelativeLayout - > 0.3 - >寫在它的底部佈局,並給物業對齊父底部如此。 在這種方法中,您的滾動視圖將按照重量指導原則僅採用0.7的屏幕,其餘按底部佈局設計。

3.)移除滾動視圖,而是使其爲線性佈局。使最高父相對佈局,並給予上述屬性的屬性對齊父底部忠於你的底部佈局和佈局到您的LinearLayout

+1

那我試過但不工作 – user3917131 2014-09-23 06:54:22

+0

因爲你的整個佈局是在scrollview,這就是爲什麼它不會工作。因爲你可以滾動,它不會調整大小。刪除滾動視圖,它會工作 – 2014-09-23 06:56:02

+0

在滾動視圖 – user3917131 2014-09-23 06:57:23

0

你應該例如設置滾動型leyout_weight爲1。並將LinearLayout的leyout_height設置爲「wrap_content」。如果將ScrollView的layout_height設置爲0dp,那很好,因此LinearLayout可以管理它。

<LinearLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical"> 

    <ScrollView 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:layout_height="0dp"> 
    </ScrollView> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      style="@style/EditText" 
      android:id="@+id/bt_reg_cancel" 
      android:text="@string/cancel" 
      android:layout_gravity="bottom" 
      android:layout_weight="1" /> 
     <Button 
      style="@style/EditText" 
      android:text="@string/save" 
      android:id="@+id/bt_reg_save" 
      android:layout_gravity="bottom" 
      android:layout_weight="1" /> 
    </LinearLayout> 


</LinearLayout> 

這應該做的伎倆。