android - 如何让水平recyclerview项目出现在recyclerview的底部

标签 android android-recyclerview

我的应用程序目前如下所示: enter image description here

如何让这些项目出现在屏幕底部?值得注意的是,这些项目在选择时会展开。

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="292dp"
        android:layout_gravity="bottom"
        android:layout_weight="
        android:orientation="horizontal"/>

编辑 1:添加了包含回收器 View 的父布局。

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="99">

        <Button
            android:id="@+id/buttonAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add"
            />

        <Button
            android:id="@+id/buttonDelete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Remove" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Edit" />
    </LinearLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="292dp"
        android:layout_gravity="bottom"
        android:layout_weight="1"
        android:orientation="horizontal" />


</LinearLayout>

最佳答案

尝试在您的布局中实现此功能:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_alignParentBottom="true"
    />
</RelativeLayout>

同样可以通过线性布局来实现:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_alignParentBottom="true"
    />
</LinearLayout>

关于android - 如何让水平recyclerview项目出现在recyclerview的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59842992/

相关文章:

java - 根据字符串移动 Recyclerview 项目位置

Android Recyclerview MediaPlayer 上一个Item声音停止,点击新一个后释放

android - 在 Webview Activity 中打开 RSS 链接

android - 如何在 Android 中显示动画弹出窗口

android - Android 中是否需要有可绘制/xxxhdpi 图像?

java - 在Recyclerview项目Mainactivity中创建url对象,Adapter在默认浏览器中解析加载Url。尝试在 WebView 中?

java - Android RecyclerView 和 onBindViewHolder

Android - 如何使用 java 文件中的计数器来定位资源/图像名称?

Android:libs 中的 .jar 文件与 gradle 中的依赖 url

android - 使用 ReverseLayout recyclerview 将项目添加到 Endless Scroll RecyclerView