Android 如何使水平回收视图显示在屏幕底部?
我想建立像下图一样的布局。当我单击按钮时,一个水平的Android 如何使水平回收视图显示在屏幕底部?,android,android-layout,android-recyclerview,Android,Android Layout,Android Recyclerview,我想建立像下图一样的布局。当我单击按钮时,一个水平的recyclerView向上滑动,并出现在包含该按钮的LinearLayout下的屏幕底部 我希望使用底部工作表。当带有recyclerView的底部工作表出现时,但它覆盖了整个LinearLayout,其中包含按钮。以下是我的布局xml: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res
recyclerView
向上滑动,并出现在包含该按钮的LinearLayout
下的屏幕底部
我希望使用底部工作表。当带有recyclerView
的底部工作表出现时,但它覆盖了整个LinearLayout
,其中包含按钮
。以下是我的布局xml:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/white"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text:"Button"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/horizontalRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_anchor="@id/bottomBar"
android:animateLayoutChanges="false"
android:scrollbars="horizontal"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>
</android.support.design.widget.CoordinatorLayout>
因此,我的问题是,如何使水平recyclerView
向上滑动并从屏幕底部显示?我走对方向了吗?还是有更好的方法来实现这一点
提前感谢。您可以使用此库 在XML中,将RecyclerView放入其布局中
<com.sothree.slidinguppanel.SlidingUpPanelLayout
您可以使用此库
在XML中,将RecyclerView放入其布局中
<com.sothree.slidinguppanel.SlidingUpPanelLayout
您可以通过简单的步骤实现:
首先,通过添加此项使线性布局方向保持垂直
android:orientation="vertical"
然后在linearLayout内的按钮下方添加recycler视图。每当需要隐藏recyclerview时,请将recyclerview的可见性保持为“已消失”,并将其显示为“可见”,如下所示
首先,将回收器隐藏在xml中,并在xml中添加这一行
android:visibility="gone"
当按下回收按钮时,使您的回收器在java中显示如下
yourRecycler.setVisibility(View.VISIBLE);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:paddingBottom="5dp"
android:layout_alignParentBottom="true"
android:paddingTop="5dp">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text="button"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/horizontalRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:animateLayoutChanges="false"
android:scrollbars="horizontal"
/>
最后,您的xml应该如下所示
yourRecycler.setVisibility(View.VISIBLE);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:paddingBottom="5dp"
android:layout_alignParentBottom="true"
android:paddingTop="5dp">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text="button"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/horizontalRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:animateLayoutChanges="false"
android:scrollbars="horizontal"
/>
您可以通过简单的步骤实现:
首先,通过添加此项使线性布局方向保持垂直
android:orientation="vertical"
然后在linearLayout内的按钮下方添加recycler视图。每当需要隐藏recyclerview时,请将recyclerview的可见性保持为“已消失”,并将其显示为“可见”,如下所示
首先,将回收器隐藏在xml中,并在xml中添加这一行
android:visibility="gone"
当按下回收按钮时,使您的回收器在java中显示如下
yourRecycler.setVisibility(View.VISIBLE);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:paddingBottom="5dp"
android:layout_alignParentBottom="true"
android:paddingTop="5dp">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text="button"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/horizontalRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:animateLayoutChanges="false"
android:scrollbars="horizontal"
/>
最后,您的xml应该如下所示
yourRecycler.setVisibility(View.VISIBLE);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:paddingBottom="5dp"
android:layout_alignParentBottom="true"
android:paddingTop="5dp">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:text="button"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/horizontalRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:animateLayoutChanges="false"
android:scrollbars="horizontal"
/>
尝试以下步骤
首先,像这样定义XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
>
<Button
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#FFF"
android:text="hello"
android:textStyle="bold"
android:layout_weight="1"
/>
<RecycleView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:visibility="gone"
>
</RecycleView>
</LinearLayout>
第二,最初设置RecycleView
visibilitygone
第三,在运行时单击按钮
设置循环查看
可见性可见
。尝试以下步骤
首先,像这样定义XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
>
<Button
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#FFF"
android:text="hello"
android:textStyle="bold"
android:layout_weight="1"
/>
<RecycleView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:visibility="gone"
>
</RecycleView>
</LinearLayout>
第二,最初设置RecycleView
visibilitygone
第三,单击按钮
在运行时设置回收视图
可见性可见
。使用底部工作表并在底部工作表内添加回收视图。尝试按照我的回答中的步骤进行操作,我测试了它。将你的recyclerview放入BottomSheet。使用BottomSheet并将recyclerview添加到BottomSheet中。尝试按照我的答案中的步骤进行操作,我测试了它。将你的recyclerview放入BottomSheet。我尝试了这个,它产生此错误视图不是CoordinatorLayout的子视图
因此recyclerview不能在线性布局中?抱歉,我的错误..我忘了添加android:layout\u alignParentBottom=“true”,这非常重要..现在检查一下..我还删除了app:layout\u anchor=“@id/bottomBar”app:layout\u行为=“android.support.design.widget.BottomSheetBehavior”这可能会导致错误我尝试了这个,它产生了这个错误视图不是CoordinatorLayout的子视图
所以recyclerview不能在线性布局中?对不起,我的错..我忘记添加android:layout\u alignParentBottom=“true“这非常重要..现在检查..同时我删除了app:layout_anchor=“@id/bottomBar”app:layout_behavior=“android.support.design.widget.BottomSheetBehavior”,这可能会导致您出现该错误