2016-12-12 7 views
0

Ich habe 2 Abschnitte in meiner Tätigkeit. Einer ist statisch mit einigen Daten und ein anderer ist ein Chat-Abschnitt mit scrollbarer Listenansicht. Als ich Daten von EditText in type_message_area und listview gebe, vergrößert sich die Größe. Listview schiebt die type_message_area hinter der weichen Tastatur. Wie kann ich das type_message_area Steuerelement beheben, um nicht hinter der Tastatur zu gehen und Listenansicht immer nach oben zu rollen.listview drängen edicttext hinter der Tastatur

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#f1f1f1" 
android:orientation="vertical" 
tools:context="com.myapp.application.ConversationActivity"> 


<!-- This FrameLayout insets its children based on system windows using 
    android:fitsSystemWindows. --> 

     <RelativeLayout 
      android:id="@+id/fullscreen_content_controls" 
      style="?metaButtonBarStyle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top|center_horizontal" 
      android:orientation="horizontal" 
      tools:ignore="UselessParent"> 

      <ImageView 
       android:id="@+id/imgUserProfile" 
       android:layout_width="35dp" 
       android:layout_height="35dp" 
       android:layout_marginStart="25dp" 
       android:layout_marginLeft="25dp" 
       android:layout_marginTop="15dp" 
       android:contentDescription="userProfileImage"/> 

      <TextView 
       android:id="@+id/nameTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:layout_marginStart="15dp" 
       android:layout_marginLeft="15dp" 
       android:layout_toEndOf="@id/imgUserProfile" 
       android:layout_toRightOf="@id/imgUserProfile" 
       android:ellipsize="marquee" 
       android:ems="12" 
       android:singleLine="true" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@android:color/primary_text_light" 
       android:textSize="18sp" 
       android:textStyle="normal"/> 

      <View android:id="@+id/separator" 
        android:background="@color/icon_gray" 
        android:layout_below="@id/nameTextView" 
        android:layout_width = "fill_parent" 
        android:layout_marginTop="4dp" 
        android:layout_height="2dip"/> 

     </RelativeLayout> 

<!-- The primary full-screen view. This can be replaced with whatever view 
is needed to present your content, e.g. VideoView, SurfaceView, 
TextureView, etc. --> 
    <RelativeLayout 
     android:id="@+id/fullscreen_content" 
     style="?metaButtonBarStyle" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="bottom|center_horizontal" 
     android:orientation="horizontal" 
     tools:ignore="UselessParent"> 
      <LinearLayout 
       android:id="@+id/outLayout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:visibility="visible"> 

       <ListView 
        android:id="@+id/msgListView" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/separator" 
        android:layout_above="@+id/type_message_area" 
        android:divider="@null" 
        android:dividerHeight="0dp" 
        android:paddingBottom="10dp"/> 

       <include 
        layout="@layout/type_message_area" 
        android:layout_width="match_parent" 
        android:layout_below="@id/msgListView" 
        android:layout_weight="1" 
        android:layout_height="wrap_content" 
        android:gravity="bottom" /> 

      </LinearLayout> 

    </RelativeLayout> 

Unten ist type_message_area.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="bottom" 
      android:orientation="horizontal"> 

<EditText 
    android:id="@+id/sendConversationEditText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textColorHint="@color/icon_gray" 
    android:textColor="@android:color/primary_text_light" 
    android:hint="@string/conversation_edit_text_hint" /> 

<Button 
    android:id="@+id/sendConversationButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/btn_solid_white" 
    android:backgroundTint="@color/primary" 
    android:text="@string/send_conversation"/> 
</LinearLayout> 

das ist meine Rolle auf listview in ConversationActivity.java

 ListView msgListView = (ListView) findViewById(R.id.msgListView); 
    //Set autoscroll of listview when a new message arrives 
    msgListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); 
    msgListView.setStackFromBottom(true); 

Antwort

0

Sie müssen das Verhalten der Tastatur auf das Aktivitätsniveau angeben. Siehe: https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

Sie haben im Grunde 2 Möglichkeiten, um Ihr Problem zu beheben. Stellen Sie die windowSoftInputMode Aktivität Attribut entweder:

  • adjustResize: Ändert die Größe Ihrer Tätigkeit die restlichen Bildschirm Immobilien zu passen. Dies kann zu einem Problem führen, bei dem die Größe der ListView Größe geändert wird und die EditText Clips nicht mehr gebunden sind.
  • adjustPan: Die Größe der Aktivität wird nicht geändert. Es schwenkt die gesamte Aktivität nach oben und richtet den unteren Rand des Eingabeelements an der Oberseite der Tastatur aus. Dies sollte AFAIK das gewünschte Ergebnis geben. (Benutzer sieht immer, was er/sie gerade schreibt)
Verwandte Themen