Android - 软键盘将我的活动布局推出屏幕

25

我的活动布局如下所示。

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

   <FrameLayout android:id="@+id/title_bar"
      android:layout_width="fill_parent"
      android:layout_height="25dip"
      android:background="@drawable/bg_title" />

   <LinearLayout android:id="@+id/main"
      android:width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
         <ListView android:id="@+id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
         <TextView android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
      </FrameLayout>
   </LinearLayout>

   <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="50dip" >
      <EditText android:id="@+id/query"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" 
         android:hint="Enter some search terms"
         android:singleLine="true" 
         android:layout_weight="1" />
      <Button android:id="@+id/btn_hide"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@drawable/btn_hide"
         android:layout_marginLeft="6dip" />
   </LinearLayout>
 </LinearLayout>
所以,搜索框固定在屏幕底部。 但是,当用户点击EditText时,软键盘会弹出并将布局推出屏幕,除了搜索框之外。 我刚开始接触Android,所以我有做错什么吗?
3个回答

51

尝试在清单文件中为您的活动添加以下内容:

android:windowSoftInputMode="adjustPan"

6
谢谢。这正是我在寻找的属性。但是,作为它的值,我不得不使用"adjustResize"来使其按照我的需求工作。 - venkatagiri
2
嗨,我也有同样的问题。但是我不能使用“adjustResize”。因为我在底部有选项卡栏。如果我使用调整大小,选项卡栏将被推到软键盘上方。我不想发生这种情况。所以如果有人有解决方案,请帮助我。 - Raj

14
对于那些感兴趣的人来说,android:windowSoftInputMode="adjustPan"android:windowSoftInputMode="adjustResize"之间的区别如下:
  • "adjustResize"
  • 活动窗口会被调整大小以为屏幕上的软键盘腾出空间。

  • "adjustPan"
  • 活动窗口的内容会自动滚动,以便当前焦点永远不会被键盘遮挡。这是为了让用户可以看到他们正在输入什么。一般来说,与调整大小相比,这通常不太理想,因为用户可能需要关闭软键盘才能访问和交互窗口的受遮挡部分。

Android文档 引用链接

5
如果您正在使用标签应用程序,您需要在添加选项卡的Activity上添加 android:windowSoftInputMode="adjustPan"。这很可能是您的启动器活动。以下是我的代码片段。
<activity
   android:label="@string/app_name"
   android:name=".MainActivity" android:windowSoftInputMode="adjustPan">
   <intent-filter >
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接