【问题标题】:Android - Soft Keyboard pushes layout of my activity out of screenAndroid - 软键盘将我的活动布局推到屏幕外
【发布时间】:2011-05-06 01:48:01
【问题描述】:

我的activity的布局如下图。

<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,所以我在这里做错了吗??

【问题讨论】:

    标签: android android-edittext android-softkeyboard


    【解决方案1】:

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

    android:windowSoftInputMode="adjustPan"
    

    【讨论】:

    • 谢谢。这是我正在寻找的属性。但是,由于它的价值,我不得不使用“adjustResize”来让它按我的需要工作。
    • 嗨,我也有同样的问题。但我不能使用“adjustResize”。因为我在底部有标签栏。如果我使用调整大小标签栏将被推到软键盘上方。我不想发生这种情况。所以如果有人有解决方案,请帮助我。
    【解决方案2】:

    有兴趣的可以看看android:windowSoftInputMode="adjustPan"android:windowSoftInputMode="adjustResize"的区别:

    “调整大小”

    调整活动窗口的大小,为屏幕上的软键盘腾出空间。

    “调整盘”

    活动窗口的内容会自动平移,因此当前焦点永远不会被键盘挡住。这样用户就可以看到他们正在输入的内容。这通常不如调整大小可取,因为用户可能需要关闭软键盘才能到达窗口的模糊部分并与之交互。

    Android Documentation

    Cited link

    【讨论】:

      【解决方案3】:

      @Raj 如果您正在使用选项卡式应用程序,则必须添加

      android:windowSoftInputMode="adjustPan"

      在您添加标签的Activity 上,这很可能是您的启动器活动。

      这是我的代码中的一个 sn-p

      <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>
      

      【讨论】:

        猜你喜欢
        • 2018-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多