2014-09-23 140 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> 

这应该做的伎俩。