Frage

Ich habe ein Layout, das eine EditText von Benutzern verwendet, um eine Datenbank zu lassen suchen und einen Listview füllen. Die EditText ist etwa 2/3 des Weges vom oberen Rand des Bildschirms (positioniert über einen Image, und von einigen Introtext gefolgt.)

Das Problem ist, dass die Soft-Tastatur der EditText versteckt, so dass der Benutzer nicht das, was die Eingabe den er sehen kann. (I deaktiviert die automatische vorschlagen.)

Ich habe versucht, Linearlayout, RelativeLayout, Polsterungen und unterschiedliche Ausrichtungen / Zentrierungen, aber ich kann es immer noch nicht an der Arbeit richtig machen. Die EditText wird entweder versteckt, wird von der oberen Rand des Bildschirms gedrückt wird, oder sich „gestaucht“ und verzerrt.

Vorschläge ???

Eine mögliche Abhilfe ist die EditText zum oberen Rand des Bildschirms zu bewegen. Dies weicht von dem Grafik-Design jedoch, dass ich gegeben wurde.

Eine weitere mögliche Abhilfe ist für mich die Soft-Tastatur öffnet in vollem Umfang nutzen zu machen (nicht sicher, wie, obwohl). Dies wird verstecken noch die EditText, aber dann kann ich die Autosuggestion wieder aktivieren, so kann der Anwender er die Typisierung sehen, was ... irgendwie ... weil er nur die Vorschläge sehen für das, was er typing.

Hier ist mein letzter Versuch. Siehe "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>
War es hilfreich?

Lösung

What you're looking for is the Activity's windowSoftInputMode attribute. You set this in your AndroidManifest.xml file, and give it a value such as:

  • adjustResize: "The activity's main window is always resized to make room for the soft keyboard on screen."

  • adjustPan: "The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window."

adjustResize will probably work for you, as long as you wrap the layout in a ScrollView. It may have negative effects if you have a bitmap image in the background, as it will be resized as well, in which case you may want to use adjustPan instead.

<activity android:windowSoftInputMode="adjustResize" />

or

<activity android:windowSoftInputMode="adjustPan" />

More information is available at the above link.

Andere Tipps

What has worked for me is to drop my highest-level LinearLayout in a scrollView (the ScrollView can only have one child). This allowed the entire activity/form to scroll up and not clutter the EditText in focus.

First, I set in my activity:

<activity android:windowSoftInputMode="adjustPan" />

Then I did the ScrollView thing I'm talking about:

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

just use following in manifest...

  <activity
        android:windowSoftInputMode="adjustPan">

try giving the edit text a layout_weight (i.e. layout_weight=1) , this may have some other effects on your other layout items that you may have to work through, but this may help it stay visible when soft keyboard pops up

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top