我有一个称为“页脚”的线性布局我想放在我的RecyclerView (API 21中引入的一种新类型列表)下面。
recyclerview可能希望具有"match_parent"高度以有效地使用内存(避免不必要的计算)。 我不应该首先使用recyclerview因为它将占用整个屏幕并且页脚不可见。 由于recyclerview在第二位, linearlayout不应该具有"match_parent"高度,因为那时将不会看到recyclerview ,并且我不需要页脚来伸展。所以我有了linearlayout "footer" ,这是我的root relativelayout第一个高度,然后linearlayout将是"match_parent" ,并在“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 have a linear layout called "footer" I want to place below my RecyclerView (a new type of list introduced in API 21).
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 the linearlayout shouldn't have a "match_parent" height, because then the recyclerview won't be seen, and I don't need the footer to stretch anyways.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>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的底部。
You just forgot to add this line
android:layout_alignParentBottom="true"to your footer layout, so to anchor it to the bottom of the RelativeLayout.
更多推荐
发布评论