2017-03-07 57 views
2

我面临的问题与Android用户界面,当键盘出现底部的按钮也弹出键盘上方。我想在出现键盘时滚动edittext(仅edittext)。这里是我的xml代码,请问任何人都可以帮我吗? 我已经试过adjustPan - 它随着屏幕一起滚动工具栏。Android用户界面问题 - 底部按钮向上滚动键盘上方

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <ScrollView 
     android:id="@+id/ScrollView01" 
     android:fillViewport="true" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:layout_width="fill_parent"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:weightSum="1.0" 
      android:layout_height="match_parent" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:id="@+id/l_layout"> 
      <EditText 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:id="@+id/editText1" 
       android:layout_marginTop="100dp"> 
       <requestFocus></requestFocus> 
      </EditText> 
      <EditText 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:id="@+id/editText2" 
       android:layout_marginTop="100dp"> 
      </EditText> 

      <EditText 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:id="@+id/editText3" 
       android:layout_marginTop="100dp"> 
       <requestFocus></requestFocus> 
      </EditText> 
      <EditText 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:id="@+id/editText4" 
       android:layout_marginTop="100dp"> 
       <requestFocus></requestFocus> 
      </EditText> 
      <EditText 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:id="@+id/editText5" 
       android:layout_marginTop="100dp"> 
       <requestFocus></requestFocus> 
      </EditText> 
     </LinearLayout> 
    </ScrollView> 
    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Go next page" 
      android:layout_alignParentRight="true" /> 
    </RelativeLayout> 
</LinearLayout> 

回答

0

完成这个任务,

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layour_alignBottom="@id/ScrollView01"> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Go next page" 
     android:layout_alignParentRight="true" /> 
</RelativeLayout> 

它会对准你下面滚动视图相对layour

+0

没有不工作。 :( – Ravi

1

您可以简单地切换您的活动的windowSoftInputMode标志 “adjustPan”。检查official documentation获取更多信息。 在android Manifest.xml文件中,添加以下内容。

<activity 
    ... 
    android:windowSoftInputMode="adjustPan"> 
</activity> 
+2

1投票链接到文档 –

+0

请再次阅读这个问题,////我已经尝试adjustPan - 它随着屏幕一起滚动工具栏。////我不希望工具栏被滚动 – Ravi

+0

@Aastha他已经告诉他,他试过使用它 –

0

尝试在你的清单

android:windowSoftInputMode="adjustResize" 
+0

这将使按钮出现在键盘上方 – Ravi

1

如果你想隐藏的键盘输入按钮,然后用下面这段代码,我刚才编辑的代码添加以下代码 -

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ScrollView01" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/l_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:orientation="vertical" 
     android:weightSum="1.0"> 

     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="100dp"> 

      <requestFocus></requestFocus> 
     </EditText> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="100dp"></EditText> 

     <EditText 
      android:id="@+id/editText3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="100dp"> 

      <requestFocus></requestFocus> 
     </EditText> 

     <EditText 
      android:id="@+id/editText4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="100dp"> 

      <requestFocus></requestFocus> 
     </EditText> 

     <EditText 
      android:id="@+id/editText5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="100dp"> 

      <requestFocus></requestFocus> 
     </EditText> 


    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:text="Go next page" /> 

    </LinearLayout> 
</ScrollView> 

但你可以滚动来显示你的按钮..

+0

我的问题是该按钮也随着keyborad弹出,我希望固定在屏幕底部的按钮总是发生任何事情 – Ravi

+0

我编辑了我的答案,如果你解决了你的问题,试试吧 – Farya

+0

按钮ig越来越隐藏,好像它超越了屏幕,我想让按钮在屏幕上显示(固定在屏幕底部),同时它不应该与键盘一起弹出 – Ravi

0

我试过你的布局与

android:windowSoftInputMode="adjustNothing" 

它似乎工作成功。

+0

但是当我把光标放在edittext上时,edtibox不会向上滚动。那就是问题了 – Ravi

0

我认为你正在寻找这一个。

activity_main.xml中

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.partharaj.ggpd.myapplication.MainActivity"> 

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

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

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textPersonName" 
       android:ems="10" 
       android:id="@+id/editText2" 
       android:hint="Name"/> 

      .... 

     </LinearLayout> 
    </ScrollView> 

    <Button 
     android:text="Button" 
     android:id="@+id/button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"/> 

</RelativeLayout> 

AndroidManifest.xml中

<activity 
    android:name=".MainActivity" 
    android:windowSoftInputMode="adjustPan"> 
    ... 
</activity> 
+0

不,该按钮不应该与键盘一起弹出。 – Ravi

+0

不工作。 2个问题。 1. EditTexts不滚动2.按钮弹出键盘。 – Ravi

+0

我知道了,我也做了同样的事情,但没有成功:( – Ravi

相关问题