Android - Soft Keyboard выталкивает макет моей активности из экрана - PullRequest
26 голосов
/ 06 ноября 2010

Макет моей активности показан ниже.

<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, Soft Keyboard появляется и выталкивает макет из экрана, кроме поля поиска.

Я только начинаю с Android, поэтому я делаючто-то здесь не так?

Ответы [ 3 ]

51 голосов
/ 06 ноября 2010

Попробуйте добавить следующее для вашей активности в манифесте:

android:windowSoftInputMode="adjustPan"
14 голосов
/ 04 июня 2014

Для тех, кто интересуется, разница между android:windowSoftInputMode="adjustPan" и android:windowSoftInputMode="adjustResize":

"adjustResize"

Размер окна действия изменен, чтобы освободить место для экранной клавиатуры на экране.

"adjustPan"

Содержимое окна действия автоматически панорамируется, поэтому текущий фокус никогда не блокируется клавиатурой. Это так, чтобы пользователь мог видеть, что он печатает. Как правило, это менее желательно, чем изменение размера, поскольку пользователю может потребоваться закрыть экранную клавиатуру, чтобы получить доступ к скрытым частям окна и взаимодействовать с ними.

Документация Android

Цитированная ссылка

5 голосов
/ 22 июня 2012

@ Raj Если вы работаете с приложением с вкладками, вы должны добавить

android:windowSoftInputMode="adjustPan"

на Activity, где вы добавляете вкладки, это, скорее всего, будет ваша активность запуска.

Вот фрагмент из моего кода

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

...