对准的LinearLayout低于RecyclerView [英] Aligning a RecyclerView below a LinearLayout
问题描述
我有一个名为页脚我希望把我下面的 RecyclerView
(新类型列表的API引入21)的线性布局。
I have a linear layout called "footer" I want to place below my RecyclerView
(a new type of list introduced in API 21).
- 的
recyclerview
可能会希望有一个match_parent
高度有效地使用内存(避免不必要的计算) 。 - 我不应该在
recyclerview
第一,因为那会占用整个屏幕和页脚不会是可见的。 - 因为
recyclerview
排第二的的LinearLayout
不应该有一个match_parent
的高度,因为那么recyclerview
不会被看到,而我不需要页脚反正伸展。
- The
recyclerview
will probably want to have a"match_parent"
height to efficiently use memory (avoid unecessary calculation). - I shouldn't have the
recyclerview
first because then it will take up the whole screen and the footer wont be visible. - Since the
recyclerview
comes second thelinearlayout
shouldn't have a"match_parent"
height, because then therecyclerview
won't be seen, and I don't need the footer to stretch anyways.
所以我有的LinearLayout
页脚
,高度先在我的根 RelativeLayout的
,那么 recyclerview
将match_parent
,和上面的页脚指定
So I have the linearlayout
"footer"
, a height first in my root relativelayout
, then the recyclerview
will be "match_parent"
, and specified above the "footer":
<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
显示。什么是我的布局上面的误解?
I know this is a layout issue only because if I remove the footer my recyclerview
is displayed. What is my misunderstanding of layouts above?
推荐答案
您刚才忘了添加此行
android:layout_alignParentBottom="true"
到您的页脚的布局,所以把它锚定到RelativeLayout的底部。
to your footer layout, so to anchor it to the bottom of the RelativeLayout.
这篇关于对准的LinearLayout低于RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!