2016-10-29 2 views
0

Ich habe einen EditText auf der Unterseite meines Layouts und ein paar TextViews auf der Oberseite. Wenn ich auf EditText klicke, bewegt es sich von unten über die Tastatur, was gut ist. Aber die TextViews bewegen sich auch nach oben und außerhalb des Bildschirms, sodass Sie sie erst sehen können, wenn Sie die Tastatur wieder schließen. Wie kann ich das vermeiden und habe trotzdem meinen EditText über der Tastatur? Ich verwende ein RelativeLayout. Danke!EditText verschiebt TextView beim Öffnen der Tastatur aus dem Bildschirm

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.ncss.tyfby.Feeling" 
android:background="#1baa84"> 

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true"> 

    <TextView 
     android:text="I am" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:id="@+id/IamTV" 
     android:layout_weight="0.10" 
     android:textSize="40sp" 
     android:textStyle="normal|bold" 
     android:gravity="bottom" /> 

    <EditText 
     android:layout_width="wrap_content" 
     android:inputType="textPersonName" 
     android:ems="10" 
     android:id="@+id/iamAdjective" 
     android:background="@android:drawable/editbox_background_normal" 
     android:hint="powerful" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:layout_marginLeft="10dp" /> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:id="@+id/send" 
     android:layout_weight="0.10" 
     android:src="@android:drawable/ic_menu_send" 
     android:background="@drawable/transparent" 
     android:onClick="send" 
     android:layout_marginLeft="5dp" /> 
</LinearLayout> 


<TextView 
    android:text="I am" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/iam1" 
    android:textSize="18sp" /> 

<TextView 
    android:text="I am" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/iam2" 
    android:textSize="18sp" 
    android:layout_below="@+id/iam1" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="10dp" /> 

<TextView 
    android:text="I am" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/iam4" 
    android:textSize="18sp" 
    android:layout_below="@+id/iam3" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="10dp" /> 

<TextView 
    android:text="I am" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/iam5" 
    android:textSize="18sp" 
    android:layout_below="@+id/iam4" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="10dp" /> 

<TextView 
    android:text="I am" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/iam3" 
    android:textSize="18sp" 
    android:layout_below="@+id/iam2" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="10dp" /> 

Screen whithout keyboardScreen with Keyboard (TextView moved out of the screen)

+0

Teilen Sie Ihr Layout xml bitte – Kushan

+0

@Yannik Pieper- Legen Sie Ihre gesamte Ansicht in Scroll, so dass Sie nach oben und sehen, Dein Inhalt. Das ist es ...... – Bhavnik

+0

Gibt es keine Option, wo ich TextView oben bleiben kann, während der editText nach oben geht? Scrollen ist in diesem Fall eine sehr schlechte Lösung ... –

Antwort

1

Sie windowSoftInputMode erkunden können, die Sie für Ihre Aktivität konfigurieren in der Datei AndroidManifest.xml: activity | Android Developers.

Vielleicht windowSoftInputMode="adjustResize" könnte für Sie nützlich sein.

Zusätzlich dazu müssen Sie Ihr Layout XML, um etwas zu ändern, wie:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    tools:context="com.ncss.tyfby.Feeling" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:orientation="vertical" 
    android:background="#1baa84"> 

    <ScrollView 
     android:layout_height="match_parent" 
     android:layout_width="wrap_content" 
     android:layout_weight="1"> 

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

      <TextView 
       android:text="I am" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/iam1" 
       android:textSize="18sp" /> 

      <TextView 
       android:text="I am" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/iam2" 
       android:textSize="18sp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginTop="10dp" /> 

      <TextView 
       android:text="I am" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/iam4" 
       android:textSize="18sp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginTop="10dp" /> 

      <TextView 
       android:text="I am" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/iam5" 
       android:textSize="18sp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginTop="10dp" /> 

      <TextView 
       android:text="I am" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/iam3" 
       android:textSize="18sp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginTop="10dp" /> 

     </LinearLayout> 

    </ScrollView> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <TextView 
      android:text="I am" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/IamTV" 
      android:layout_weight="0.10" 
      android:textSize="40sp" 
      android:textStyle="normal|bold" 
      android:gravity="bottom" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:inputType="textPersonName" 
      android:ems="10" 
      android:id="@+id/iamAdjective" 
      android:background="@android:drawable/editbox_background_normal" 
      android:hint="powerful" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:layout_marginLeft="10dp" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/send" 
      android:layout_weight="0.10" 
      android:src="@android:drawable/ic_menu_send" 
      android:background="@drawable/transparent" 
      android:onClick="send" 
      android:layout_marginLeft="5dp" /> 

    </LinearLayout> 

</LinearLayout> 
+0

, wenn ich adjustResize addiere, bleibt der editText am unteren Rand des Layouts, wenn die Tastatur auftaucht, so dass du sie nicht sehen kannst. –

+0

Dann sollten Sie wahrscheinlich in Betracht ziehen, was @Mohammad Z in seiner Antwort vorgeschlagen hat, und zusätzlich Ihr Layout in ein 'ScrollView' einbinden. –

+0

Ich habe es genau so gemacht, wie du es mir gezeigt hast, aber die TextViews bewegen sich immer noch über den Bildschirm, wenn die Tastatur geöffnet wird. –

0

Sie sollen Ihr gesamtes Layout innerhalb eines Scroll setzen und dass oberhalb von my_edit_text erzwingen:

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/my_edit_text"> 
+0

Soll ich RelativeLayout durch ScrollView ersetzen? –

+0

Nein, setze es einfach in deine 'ScrollView' –

Verwandte Themen