3
我有一个名为“footer”的线性布局,我想将它放在我的RecyclerView
(API 21中引入的一种新类型的列表)的下方。在LinearLayout下方对齐RecyclerView
- 的
recyclerview
可能会希望有一个"match_parent"
高度有效地使用内存(避免不必要的计算)。 - 我不应该第一次使用
recyclerview
,因为它会占用整个屏幕,页脚不会被看到。 - 由于
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
显示。我对上面的布局有什么误解?
您有问题吗?你能形容它吗? – 2014-11-01 18:11:52
所显示的只是屏幕顶部附近的页脚,而不是回收站视图,然后是页面下方的页脚。 – 2014-11-01 19:17:35
您只是忘了将'android:layout_alignParentBottom =“true”'添加到您的页脚布局,以便将它锚定到RelativeLayout的底部。 – 2014-11-01 19:59:56