2014-11-01 7 views
3

У меня есть линейный макет под названием «footer». Я хочу разместить ниже своего RecyclerView (новый тип списка, представленный в API 21).Выравнивание RecyclerView под LinearLayout

  1. recyclerview, вероятно, хотят иметь "match_parent" высоту, чтобы эффективно использовать память (во избежание ненужного расчета).
  2. Сначала я не должен был иметь recyclerview, потому что тогда он займет весь экран, а нижний колонтитул не будет виден.
  3. Поскольку recyclerview занимает второе место, linearlayout не должен иметь высоту "match_parent", потому что тогда recyclerview не будет видно, и мне не нужен нижний колонтитул в любом случае.

Так у меня есть linearlayout"footer", высота первый в моем корне relativelayout, то recyclerview будет "match_parent", и указанное выше «сноска»:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
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"> 

<LinearLayout 
    android:id="@+id/footer" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <ImageView 
     android:id="@+id/addTaskImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end" 
     android:src="@drawable/ic_edit" 
     android:visibility="visible" /> 

    <RelativeLayout 
     android:id="@+id/addTaskRL" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="gone"> 

     <EditText 
      android:id="@+id/taskET" 
      android:layout_width="match_parent" 
      android:layout_height="150sp" 
      android:background="@color/White"> 
     </EditText> 

     <RelativeLayout 
      android:id="@+id/paletteRed" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_below="@id/taskET" 
      android:layout_marginLeft="50dp" 
      android:layout_marginTop="10dp" 
      android:background="@color/Red" /> 

     <RelativeLayout 
      android:id="@+id/paletteOrange" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_below="@id/taskET" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_toRightOf="@id/paletteRed" 
      android:background="@color/Orange" /> 

     <RelativeLayout 
      android:id="@+id/paletteGreen" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_below="@id/taskET" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_toRightOf="@id/paletteOrange" 
      android:background="@color/Green" /> 

     <RelativeLayout 
      android:id="@+id/paletteRoyalBlue" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_below="@id/taskET" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_toRightOf="@id/paletteGreen" 
      android:background="@color/RoyalBlue" /> 

     <RelativeLayout 
      android:id="@+id/palettePurple" 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_below="@id/taskET" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_toRightOf="@id/paletteRoyalBlue" 
      android:background="@color/Purple" /> 

     <Button 
      android:id="@+id/submitBtn" 
      android:layout_width="70dp" 
      android:layout_height="30dp" 
      android:layout_below="@id/taskET" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_toRightOf="@id/palettePurple" 
      android:background="@color/SkyBlue" 
      android:textColor="@color/White" 
      android:text="@string/submit"> 
     </Button> 
    </RelativeLayout> 
</LinearLayout> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/tasksRV" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@id/footer"/> 
</RelativeLayout> 

Я знаю, что это проблема макета только потому, что, если я удалю нижний колонтитул, появится recyclerview. Каково мое недопонимание макетов выше?

+0

У вас возникли проблемы? Вы можете это описать? –

+0

Все, что отображается, это нижний колонтитул в верхней части экрана, а не вид ресайклера, затем нижний колонтитул под ним. –

+1

Вы просто забыли добавить 'android: layout_alignParentBottom =" true "' в макет нижнего колонтитула, чтобы привязать его к нижней части RelativeLayout. –

ответ

1

Вы просто забыли добавить эту строку

android:layout_alignParentBottom="true" 

в макете колонтитула, поэтому привязать его к нижней части RelativeLayout.

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