4

У меня есть RelativeLayout с EditText, у которого есть Button под ним. В идеале, когда пользователь нажимает EditText и заполняет несколько строк текста, RelativeLayout также будет расширяться по мере увеличения линий. Тем не менее, поведение, которое у меня сейчас есть, заключается в том, что после заполнения первой строки EditText клавиатура начинает покрывать Button ниже нее, а после 3-4 строк текста в EditTextButton ушел под клавиатуру. Есть ли способ получить его так, чтобы при вводе текста весь макет увеличивался в размере, чтобы кнопка оставалась над клавиатурой? Вот мой код:Softkeyboard скрывает кнопку ниже многострочного EditText?

AndroidManifest.xml:

<activity 
     android:name="<Name of project>.activity.Comments" 
     android:configChanges="orientation|keyboardHidden" 
     android:label="Comments" 
     android:screenOrientation="portrait" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:windowSoftInputMode="stateHidden|adjustResize" /> 

Comments.xml:

<RelativeLayout 
     android:id="@+id/send_message" 
     android:layout_width="match_parent" 
     android:layout_height="90dp" 
     android:layout_margin="4dp" 
     android:layout_alignParentBottom="true"> 

     <EditText 
      android:fontFamily="sans-serif" 
      android:id="@+id/write_comment" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="12dp" 
      android:gravity="left" 
      android:textSize="16sp" 
      android:textColor="@color/black" 
      android:cursorVisible="false" 
      android:textColorHint="@color/material_color_grey_300" 
      android:hint="@string/commentBack" 
      android:background="@drawable/edittext_bg" 
      android:inputType="textMultiLine" 
      android:isScrollContainer="true" 
      android:maxLength="200" 
      android:scrollHorizontally="false" /> 

     <Button 
      android:fontFamily="sans-serif-medium" 
      android:id="@+id/send_comment" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="16sp" 
      android:textColor="@color/colorPrimary" 
      android:layout_marginTop="8dp" 
      android:text="@string/send" 
      android:background="@null" 
      android:layout_below="@id/write_comment" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentBottom="true" 
      android:textAllCaps="false" /> 
    </RelativeLayout> 

Я пытался добавить android:isScrollContainer="true" мысли, что было бы создать контейнер прокрутки в EditText так что это поможет расширить макет, но это, похоже, не сработало. Любая помощь будет оценена по достоинству. Благодаря!

Edit: Добавлен в целом макет на основе ответа ниже:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    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="match_parent" android:fitsSystemWindows="true" 
    android:id="@+id/comments_layout"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/comments_appbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="?attr/actionBarSize" 
      android:layout_width="match_parent" 
      android:id="@+id/comments_listview" 
      android:layout_height="match_parent"> 

      <ListView 
       android:scrollbars="vertical" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/rv_view_comments"> 
      </ListView> 

      <TextView 
       android:layout_below="@id/rv_view_comments" 
       android:gravity="center_horizontal" 
       android:padding="16dp" 
       android:textSize="16sp" 
       android:id="@+id/empty_list_item" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:visibility="gone" 
       android:text="@string/noComments" > 
      </TextView> 

      <include layout="@layout/include_progress_overlay"/> 

     </RelativeLayout> 

     <RelativeLayout 
    android:id="@+id/send_message" 
    android:layout_width="match_parent" 
    android:layout_height="90dp" 
    android:layout_margin="4dp" 
    android:layout_alignParentBottom="true"> 

    <EditText 
     android:fontFamily="sans-serif" 
     android:id="@+id/write_comment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="12dp" 
     android:gravity="left" 
     android:textSize="16sp" 
     android:textColor="@color/black" 
     android:cursorVisible="false" 
     android:textColorHint="@color/material_color_grey_300" 
     android:hint="@string/commentBack" 
     android:background="@drawable/edittext_bg" 
     android:inputType="textMultiLine" 
     android:isScrollContainer="true" 
     android:maxLength="200" 
     android:scrollHorizontally="false" /> 

    <Button 
     android:fontFamily="sans-serif-medium" 
     android:id="@+id/send_comment" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="16sp" 
     android:textColor="@color/colorPrimary" 
     android:layout_marginTop="8dp" 
     android:text="@string/send" 
     android:background="@null" 
     android:layout_below="@id/write_comment" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentBottom="true" 
     android:textAllCaps="false" /> 
</RelativeLayout> 

    </RelativeLayout> 

</android.support.design.widget.CoordinatorLayout> 

Edit: По просьбе Jaydroider, я включил фотографию, чтобы показать мою проблему. Если бы я мог сделать GIF или что-то, если я добавить текст в мой EditText поле, кнопка Send исчезнет под клавиатурой и, если я не удалить текст из EditText, то `Отправить не может быть выдвинут:

Image showing problem

Редактировать: Я также показал, как я прокручиваю нижнюю часть своего ListView, когда я нажимаю на EditText здесь, если это помогает.

public void setupComment(final EditText comment) { 
     //Once we send the post, we want to scroll to bottom of listview 
     comment.setOnEditorActionListener(new TextView.OnEditorActionListener() { 

      @Override 
      public boolean onEditorAction(TextView v, int actionId, 
              KeyEvent event) { 
       if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { 
        comment.setImeOptions(EditorInfo.IME_ACTION_DONE); 
        resetKeyboardSettings(); 
       } 
       return false; 
      } 
     }); 

     //Hide the cursor until view is clicked on 
     View.OnTouchListener onTouchListener = new View.OnTouchListener(){ 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       System.out.println("Touched"); 
       if (v.getId() == comment.getId()) { 
        comment.setCursorVisible(true); 
       } 
       commentsView.postDelayed(new Runnable() { 
        @Override 
        public void run() { 

         commentsView.smoothScrollToPosition(commentsView.getAdapter().getCount()); 
        } 
       }, 750); 
       return false; 
      } 
     }; 
     comment.setOnTouchListener(onTouchListener); 
    } 
+0

Когда я проверил ваш макет, я могу видеть «Просмотр списка» без каких-либо других виджетов. Пожалуйста, уточните подробнее. –

+0

@jaydroider Я обновил приведенный выше код, чтобы продемонстрировать свою проблему. Надеюсь, это поможет. В разделе «Редактирование» указано «Редактировать: добавлено во весь макет» на основе нижеприведенного ответа: « – user1871869

+0

Да, я уже проверил этот макет на моей стороне, мне нужно уточнить, где будут отображаться« редактировать текст »и« кнопка ». с этим макетом в настоящее время я могу видеть только «Просмотр списка». –

ответ

2

Я пробовал с вашим Layout все идеально с этим не проблема.

But you need to make changes to your manifest where you declared your activity Использование дополнительных свойств для android:configChanges.

Сделайте это внутри своего файла android manifest.xml.

 <activity 
      android:name="<Name of project>.activity.Comments" 
      android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" 
      android:label="Comments" 
      android:screenOrientation="portrait" 
      android:theme="@style/AppTheme.NoActionBar" 
      android:windowSoftInputMode="stateHidden|adjustResize"/> 

Вот XML, который я использовал.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/comments_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.PopupOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/comments_appbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout 
      android:id="@+id/comments_listview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/send_message" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="?attr/actionBarSize"> 

      <ListView 
       android:id="@+id/rv_view_comments" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_toEndOf="@+id/empty_list_item" 
       android:scrollbars="vertical" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

      <TextView 
       android:id="@+id/empty_list_item" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/rv_view_comments" 
       android:gravity="center_horizontal" 
       android:padding="16dp" 
       android:text="No Comments" 
       android:textSize="16sp" 
       android:visibility="gone" /> 


     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/send_message" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_margin="4dp"> 

      <EditText 
       android:id="@+id/write_comment" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#FFFFFF" 
       android:cursorVisible="false" 
       android:fontFamily="sans-serif" 
       android:gravity="left" 
       android:hint="Comment Back" 
       android:inputType="textMultiLine" 
       android:isScrollContainer="true" 
       android:maxLength="200" 
       android:padding="12dp" 
       android:scrollHorizontally="false" 
       android:textColor="#000000" 
       android:textColorHint="@android:color/holo_red_dark" 
       android:textSize="16sp" /> 

      <Button 
       android:id="@+id/send_comment" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_below="@id/write_comment" 
       android:layout_marginTop="8dp" 
       android:background="@null" 
       android:fontFamily="sans-serif-medium" 
       android:gravity="center|center_vertical" 
       android:text="Send" 
       android:textAllCaps="false" 
       android:textColor="@color/colorPrimary" 
       android:textSize="16sp" /> 
     </RelativeLayout> 

    </RelativeLayout> 

</android.support.design.widget.CoordinatorLayout> 

I have tested with above changes and it's just working fine you can see below.

enter image description here

Надеется, что это поможет вам решить вашу проблему.

+0

Эй, не возражаете ли вы опубликовать свой код, чтобы я мог имитировать его? Я попытался выслушать ваши изменения в файле «Manifest», но это, похоже, не исправило его для меня. – user1871869

+0

@ user1871869 Какой код вам нужен? –

+0

Ваш код макета XML, который вы использовали для создания изображения выше? – user1871869

0

Попробуйте это:

<RelativeLayout 
     android:id="@+id/send_message" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="4dp" 
     android:layout_alignParentBottom="true"> 

     <EditText 
      android:fontFamily="sans-serif" 
      android:id="@+id/write_comment" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="12dp" 
      android:gravity="left" 
      android:textSize="16sp" 
      android:textColor="@color/black" 
      android:cursorVisible="false" 
      android:textColorHint="@color/material_color_grey_300" 
      android:hint="@string/commentBack" 
      android:background="@drawable/edittext_bg" 
      android:inputType="textMultiLine" 
      android:isScrollContainer="true" 
      android:maxLength="200" 
      android:scrollHorizontally="false" /> 

     <Button 
      android:fontFamily="sans-serif-medium" 
      android:id="@+id/send_comment" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="16sp" 
      android:textColor="@color/colorPrimary" 
      android:layout_marginTop="8dp" 
      android:text="@string/send" 
      android:background="@null" 
      android:layout_below="@id/write_comment" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentBottom="true" 
      android:textAllCaps="false" /> 
    </RelativeLayout> 
+0

Эй, я пытался следовать вашему коду. Похоже, вы просто добавили 'android: layout_height = wrap_content' в тег RelativeLayout. Я попытался реализовать ваше предложение, но это, похоже, не работает, и теперь «ListView» у меня есть мой «EditText». Я разместил весь свой макет выше в надежде, что это станет более понятным и поможет мне исправить эту проблему. Я попробовал то, что вы упомянули выше, но поскольку «EditText» был скрыт, я не был уверен, как это исправить. – user1871869

0

Положите все ваши редактировать тексты и кнопки в представлении прокрутки.

<ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 
       <Edittext 
       <EditText 
       <EditText 
       <Btn 
      </LinearLayout 
     </scrollview 
0

Мое решение было бы добавить ScrollView как вид корня в макете и Override onSizeChanged метод представления. Если высота EditText увеличивается, и клавиатура блокирует вашу кнопку, Smooth Scroll на вашу кнопку.

Надеюсь, это поможет.

+0

Как бы я использовал 'ScrollView' с вложенным' ListView'? Я вижу, что вы говорите, но я чувствую, что это не сработает в моем случае. – user1871869

 Смежные вопросы

  • Нет связанных вопросов^_^