2016-02-08 3 views
0

У меня есть CoordinatorLayout, где RecyclerView отображает некоторые CardViews, определенные в другом макете. В этом прокручиваемом представлении я пытаюсь добавить RelativeLayout, который наследует поля для ввода текста, кнопки для его отправки и т. Д.Использование RelativeLayout снаружи CoordinatorView

Проблема: CoordinatorLayout, кажется, блокирует весь экран, хотя я сказал, чтобы обернуть высоту содержимого. Тем не менее, добавлен RelativeLayout (проверено его установкой Coordinator-height = 50dp), но вне экрана. Что здесь не так?

PS: Я знаю, как его решить с помощью android:layout_weight=xx. Но это не то, чего я хочу достичь, потому что он блокирует мой EditText для расширения, если вводятся большие тексты.

<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:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/data_coordinator_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      /> 


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

    <RelativeLayout 
     android:id="@+id/delete_data_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_below="@id/data_coordinator_layout"> 

     <EditText/> 
     <Button/> 
     <Button/> 
     <Button/> 

    </RelativeLayout> 


</RelativeLayout> 
+0

в "data_coordinator_layout", dont u mean width = match и height = wrap? – MeGoodGuy

+0

Да, правильно! Как видно в layout.xml –

+0

sry я имел в виду «+ id/delete_data_layout» – MeGoodGuy

ответ

0

Это на самом деле довольно просто. Вам нужно выровнять свой Relative Layout (delete_data_layout) до нижней части вашего родителя. Затем вы создадите схему Координатора над сравнительной компоновкой. Это приводит к тому, что расположение координатора всегда будет оставаться выше относительной компоновки - даже когда Edittext будет расширяться.

Вот XML.

<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:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/data_coordinator_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_above="@+id/delete_data_layout"> <---- Change here 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

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

    <RelativeLayout 
     android:id="@+id/delete_data_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true"> <---- Change here 

     <EditText/> 
     <Button/> 
     <Button/> 
     <Button/> 

    </RelativeLayout> 

</RelativeLayout> 
Смежные вопросы