【问题标题】:Aligned parent bottom relative layout hides recycler view对齐的父底部相对布局隐藏回收器视图
【发布时间】:2017-03-08 23:03:49
【问题描述】:

我一直在到处寻找这个问题。 我已经将一个 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>

【问题讨论】:

    标签: android alignment


    【解决方案1】:

    设置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>
    

    【讨论】:

    • 我的错...我在 recyclerview 上添加了 layout_above
    【解决方案2】:

    试试下面的代码。

    <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,我们可以避免这种情况。

    【讨论】:

      【解决方案3】:

      您没有发布完整的代码。但在您的情况下,您只需创建一个 LinearLayout 并设置android:layout_alignParentBottom="true"。没关系..
      但是在包含 Recycler 的 Linearlayout 中,您要添加此 android:layout_below="@+id/comments"。仅此还不够。您需要添加 布局上方属性

      android:layout_above="@+id/bottomLayout"
      

      【讨论】:

        【解决方案4】:

        尝试在包含Recycler的LinearLayout上添加一个paddingBottom,与Recycler中的Adapter高度一致

        【讨论】:

        • 是的,但我不想动态更改我认为在 axml 级别有解决方案
        【解决方案5】:

        将LinearLayout改为Recycler下方的RelativeLayout

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-10-04
          • 1970-01-01
          • 2021-06-30
          • 2017-02-16
          相关资源
          最近更新 更多