2016-12-12 2 views
0

У меня есть 2 раздела в моей деятельности. Один из них является статичным с некоторыми данными, а другой - секцией чата с прокручиваемым списком. Когда я ввожу данные от EditText в type_message_area и listview, размер увеличивается. Listview выдвигает type_message_area за мягкой клавиатурой. Как я могу исправить элемент управления type_message_area, чтобы не отставать от клавиатуры, а список всегда прокручивается вверх.listview pushing edittext за клавиатурой

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

Ниже 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> 

это мой свиток на listview в 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); 

ответ

0

Вы должны указать поведение клавиатуры на уровне активности. См.: https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

У вас в основном есть 2 варианта, чтобы исправить вашу проблему. Установите windowSoftInputMode активность приписывать либо:

  • adjustResize: Изменяет вашу деятельность, чтобы соответствовать оставшейся площади экрана. Это может вызвать проблему, при которой размер ListView будет изменен, а клипы EditText не будут связаны.
  • adjustPan: Не меняет размер своей деятельности. Он перемещает всю активность вверх и выравнивает нижнюю часть входного элемента с верхней частью вашей мягкой клавиатуры. Это должно дать AFAIK желаемый результат. (пользователь всегда видит, что он в настоящее время печатает)
Смежные вопросы