20

EditTextを使用して、ユーザーがデータベースを検索し、ListViewにデータを入力できるようにするレイアウトがあります。EditTextは、画面の上部から約2/3のところにあります(ImageViewの上に配置され、その後にイントロテキストが続きます)。

問題は、ソフトキーボードがEditTextを非表示にするため、ユーザーが入力内容を確認できないことです。(自動提案を無効にしました。)

LinearLayout、RelativeLayout、パディング、およびさまざまな配置/センタリングを試しましたが、それでも正しく機能させることができません。EditTextは非表示になっているか、画面の上部から押し出されているか、「押しつぶされて」歪んでいます。

提案???

考えられる回避策の1つは、EditTextを画面の上部に移動することです。しかし、これは私が与えられたグラフィックデザインから逸脱しています。

もう1つの考えられる回避策は、ソフトキーボードを全画面で開くようにすることです(ただし、方法はわかりません)。これでもEditTextは非表示になりますが、自動提案を再度有効にして、ユーザーが入力内容を確認できるようにすることができます。ユーザーは入力内容の提案しか表示できないためです。

これが私の最新の試みです。「introFrame」を参照してください。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content" 
 android:layout_height="fill_parent"
 android:orientation="vertical">

 <LinearLayout android:id="@+id/titleContainer"
  android:orientation="horizontal" android:layout_width="fill_parent"
  android:layout_height="wrap_content">
  <TextView android:text="@string/title_string"
   android:textSize="15sp" android:textColor="#FFFFFF"
   android:textStyle="bold" android:paddingLeft="5dp"
   android:layout_height="fill_parent" android:layout_width="wrap_content" />
 </LinearLayout>

 <FrameLayout 
 android:id="@+id/introFrame"
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content"
 android:gravity="center_horizontal" >
 <ImageView 
  android:src="@drawable/main_search_image"
  android:scaleType="center"
  android:layout_gravity="center"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"/>
 <LinearLayout
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:paddingTop="140dp" >
  <LinearLayout android:id="@+id/introSearchContainer"
   android:orientation="horizontal" 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center_vertical" >
   <LinearLayout 
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
    <EditText android:id="@+id/intro_search_box" 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:hint="     Enter keyword     " 
     android:imeOptions="actionGo"   
     android:inputType="textFilter" 
     android:maxLines="1" />
   </LinearLayout>
   <LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <Button android:id="@+id/intro_search_button" 
     android:background="@drawable/custom_button_go"
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" />
    </LinearLayout>
  </LinearLayout>
  <TextView
   android:text="@string/search_intro"
   android:textSize="15sp"
   android:textColor="#FFFFFF"
   android:layout_height="wrap_content"
   android:layout_width="fill_parent" /> 
 </LinearLayout>
 </FrameLayout>

 <LinearLayout android:id="@+id/listContainer"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ListView android:id="@+id/itemlist" android:layout_width="wrap_content"
   android:layout_height="wrap_content" android:cacheColorHint="#00000000" />
  <TextView android:text="No data found" android:layout_width="fill_parent"
   android:layout_height="fill_parent" android:gravity="center"
   android:textSize="16sp" android:textColor="#FFFFFF" android:id="@+id/android:empty" />
 </LinearLayout>

</LinearLayout>
4

4 に答える 4

57

探しているのはアクティビティのwindowSoftInputMode属性です。これをAndroidManifest.xmlファイルで設定し、次のような値を指定します。

  • adjustResize:「アクティビティのメインウィンドウは、画面上のソフトキーボード用のスペースを確保するために常にサイズ変更されます。」

  • adjustPan:「アクティビティのメインウィンドウは、ソフトキーボード用のスペースを確保するためにサイズ変更されません。むしろ、ウィンドウのコンテンツが自動的にパンされるため、現在のフォーカスがキーボードによって隠されることはなく、ユーザーは入力内容を常に確認できます。これは一般に、サイズ変更よりも望ましくありません。これは、ユーザーがウィンドウの隠された部分にアクセスして操作するために、ソフトキーボードを閉じる必要がある場合があるためです。」

レイアウトをScrollViewでラップする限り、adjustResizeはおそらく機能します。背景にビットマップ画像がある場合は、サイズも変更されるため、悪影響が生じる可能性があります。その場合は、代わりにadjustPanを使用することをお勧めします。

<activity android:windowSoftInputMode="adjustResize" />

また

<activity android:windowSoftInputMode="adjustPan" />

詳細については、上記のリンクをご覧ください。

于 2010-12-13T20:16:04.243 に答える
13

私にとってうまくいったのは、最高レベルのLinearLayoutをscrollViewにドロップすることです(ScrollViewは子を1つだけ持つことができます)。これにより、アクティビティ/フォーム全体を上にスクロールして、フォーカスのあるEditTextを乱雑にすることがなくなりました。

まず、アクティビティを開始しました。

<activity android:windowSoftInputMode="adjustPan" />

それから私は私が話しているScrollViewのことをしました:

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

    <!-- STUFF -->

  </LinearLayout>
</ScrollView>
于 2012-01-04T22:40:59.547 に答える
3

マニフェストで以下を使用するだけです...

  <activity
        android:windowSoftInputMode="adjustPan">
于 2016-06-01T05:21:45.307 に答える
1

編集テキストにlayout_weight(つまり、layout_weight = 1)を指定してみてください。これにより、他のレイアウトアイテムに影響を与える可能性がありますが、ソフトキーボードがポップアップしたときに表示されたままになる可能性があります。

于 2010-12-13T20:05:12.200 に答える