13

Ich habe eine Ansicht mit einigen Feldern (Namen, E-Mail, Passwort, registriert Taste):Wie macht man eine Android-Ansicht scrollbar, wenn die Tastatur erscheint?

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

    <ViewFlipper 
     android:id="@+id/viewflipper" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     //Layouts 

    </ViewFlipper> 

</ScrollView> 

Wenn ich ein EditText Feld konzentrieren, die Tastatur erscheint und die unteren Felder auf der Ansicht überlagert. So kann ich sie nicht sehen, wenn die Tastatur vorhanden ist. Ich würde gerne wissen, wie man die Ansicht scrollbar macht, damit ich die unteren Felder sehen kann. Und außerdem, wie Sie die Ansicht automatisch scrollen lassen, um das fokussierte Feld sichtbar zu machen.

Antwort

37

Sie benötigen android:windowSoftInputMode="adjustResize" Attribut für Ihre Aktivität in der AndroidManifest.xml-Datei aufgenommen werden - und dann Android sollte für Sie automatisch die Größe neu bestimmen tun:

<activity android:name="..." 
      ... 
      android:windowSoftInputMode="adjustResize"> 
    ... 
/> 
+1

Eigentlich war es eingestellt "adjustPan | adjustResize". Durch das Entfernen von adjustPan funktionierte es. Vielen Dank! – Alexis

0

Haben Sie versucht:

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

<ViewFlipper 
    android:id="@+id/viewflipper" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/scroll_container"> 
     //Layouts 
    </ScrollView> 


</ViewFlipper> 

6

Ich habe eine einfache XML-Datei erstellt, hoffe, das ist, was Sie suchen.

Schritt 1. Sie können blättern, wenn das Tastenfeld angezeigt wird.

Schritt 2. Wenn Sie auf Text-Feld klicken, erscheint Focus/oberhalb der Tastatur.

<ScrollView android:id="@+id/ScrollView01" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillViewport="true" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:weightSum="1.0" 
    android:layout_height="match_parent" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:id="@+id/l_layout"> 
    <EditText 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/editText1" 
     android:layout_marginTop="100dp"> 
     <requestFocus></requestFocus> 
    </EditText> 
    <EditText 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/editText2" 
     android:layout_marginTop="100dp"> 
     </EditText> 
    </LinearLayout> 
</ScrollView> 
+0

Ich hatte ein Problem mit einem Scrollview und fillViewport ist genau das, was ich brauchte. – AlexBrand

0

In meinem Fall @Aleks G Lösung funktionierte nicht. so löste ich mein problem mit

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/registration_scroll_view" 
    android:layout_alignParentTop="true" 
    android:layout_above="@+id/btn_register_submit" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <!--This comment will be replaced 
      by your focusable views--> 

    </LinearLayout> 
</ScrollView> 

<Button 
    android:id="@+id/btn_register_submit" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_alignParentBottom="true" 
    android:background="@drawable/form_action_button_green" 
    android:gravity="center" 
    android:text="@string/submit" 
    /> 

</RelativeLayout> 
Verwandte Themen