LinearLayout下面是动态RecyclerView listview

问题描述 投票:1回答:2

我有一个动态列表和最后一项下面的静态线性布局。当列表为空时,LinearLayout位于页面顶部。

每当我在列表中添加元素时,LinearLayout就会移动到列表的最后一项之下。当列表变长时,静态LinearLayout应保持在屏幕的末尾。我已经画了一些例子来更好地理解。

enter image description here

但每当我添加7个元素时,我的线性布局隐藏在列表下方。

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/app_margin"
        android:id="@+id/group_manage_list_view"
        android:paddingBottom="40dp"
        />

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_below="@+id/group_manage_list_view"
          >

            <Button
                android:layout_width="34dp"
                android:layout_height="34dp"
                android:background="@drawable/ic_add_circle_outline_white_24dp"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/app_margin"
                android:backgroundTint="@color/headline_grey"
                android:id="@+id/create_group_button_click"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/add_group"
                android:layout_marginLeft="@dimen/app_margin"
                android:layout_gravity="center_vertical"
               />


        </LinearLayout>

    </RelativeLayout>
android android-layout recyclerview-layout
2个回答
1
投票

你可以使用android:layout_weight来达到这个目的,但是你必须保持你的recycleviewlinearlayout的可见性,比如数组大小大于零而不是让它看得见,否则反之亦然

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/group_manage_list_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.8"
        android:padding="10dp"
        android:paddingBottom="40dp"
        android:visibility="gone" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.2"
        android:minHeight="50dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/create_group_button_click"
            android:layout_width="34dp"
            android:layout_height="34dp"
            android:layout_gravity="top"
            android:layout_marginLeft="10dp"
            android:background="@drawable/ic_launcher_background"
            android:backgroundTint="@color/colorAccent" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_marginLeft="10dp"
            android:text="add_group" />

    </LinearLayout>

</LinearLayout>

1
投票

我想你需要使用NestedScrollView,这里是示例代码。希望这可以帮到你。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Seomthing" />
        </LinearLayout>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>

如果这有帮助,请给我答案。快乐编码..

© www.soinside.com 2019 - 2024. All rights reserved.