![](/img/trans.png)
[英]View aligned to parent bottom is hiding, while including relative layout inside coordinator layout
[英]Aligned parent bottom relative layout hides recycler view
我一直在到處尋找這個問題。 我已經將LinearLayout對齊到父級相對布局的底部,還對齊了RecyclerView,作為同一級別的子級,問題是列表未檢測到底部的元素,並且滾動到最后,所以我看不到最后一個列表的行。 這是我的代碼:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginTop="10dp"
android:clipToPadding="false"
android:clipChildren="false"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--some code-->
<LinearLayout
android:layout_below="@+id/comments"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewComments"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:shadowColor="#000"
android:shadowDx="-2"
android:shadowRadius="8"
android:shadowDy="-10"
android:layout_marginTop="10dp"
android:layout_height="wrap_content">
<!--some code-->
</LinearLayout>
</RelativeLayout>
嘗試下面的代碼。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginTop="10dp"
android:clipToPadding="false"
android:clipChildren="false"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--some code-->
<LinearLayout
android:id="@+id/recyclerViewContainer"
android:layout_below="@+id/comments"
android:layout_above="@+id/bottomLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewComments"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottomLinearLayout"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:shadowColor="#000"
android:shadowDx="-2"
android:shadowRadius="8"
android:shadowDy="-10"
android:layout_marginTop="10dp"
android:layout_height="wrap_content">
<!--some code-->
</LinearLayout>
</RelativeLayout>
基本上,底部的LinearLayout與RecyclerView重疊。 通過在RecyclerView的父布局上使用android:layout_above
,我們可以避免這種情況。
設置android:layout_above
屬性以設置recyclerView的容器,直到頁腳
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginTop="10dp"
android:clipToPadding="false"
android:clipChildren="false"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--some code-->
<LinearLayout
android:layout_below="@+id/comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/aLayout">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewComments"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent" />
</LinearLayout>
<LinearLayout
android:id="@+id/aLayout"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:shadowColor="#000"
android:shadowDx="-2"
android:shadowRadius="8"
android:shadowDy="-10"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--some code-->
</LinearLayout>
</RelativeLayout>
您沒有發布完整的代碼。 但是在您的情況下,您只需創建LinearLayout並設置android:layout_alignParentBottom="true"
。 還行吧..
但是,在包含回收站的Linearlayout中,您要添加此android:layout_below="@+id/comments"
。 僅這還不夠。 您需要在屬性上方添加布局
android:layout_above="@+id/bottomLayout"
嘗試在LinearLayout上添加一個paddingBottom,該底部包含與Recycler中的適配器具有相同高度的Recycler
將LinearLayout更改為RelativeLayout,其位於回收站下方
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.