当前位置: 首页 > 知识库问答 >
问题:

滚动回收器同时查看垂直和水平

寿意远
2023-03-14

我想制作一个类似视图的电子表格来显示一些数据。到目前为止,这是我所拥有的,但我一次只能滚动一种方式。我希望能够同时水平和垂直滚动。

现在我有一个水平滚动视图内的回收器视图。

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

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

</HorizontalScrollView>

这是我的回收器查看行布局。

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/change_log_table_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:focusable="true">

<TableRow>

    <TextView
        android:id="@+id/change_log_flavor_name"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:gravity="center_horizontal"
        android:maxLines="3"
        android:textSize="16sp"/>

    <View
        android:layout_width="0.5dp"
        android:layout_height="match_parent"
        android:background="@android:color/darker_gray"/>

    <TextView
        android:id="@+id/change_log_batch_number"
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:gravity="center_horizontal"
        android:maxLines="3"
        android:textSize="16sp"/>

    <View
        android:layout_width="0.5dp"
        android:layout_height="match_parent"
        android:background="@android:color/darker_gray"/>


    <TextView
        android:id="@+id/change_log_date"
        android:layout_width="110dp"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:gravity="center_horizontal"
        android:maxLines="3"
        android:textSize="16sp"/>

    <View
        android:layout_width="0.5dp"
        android:layout_height="match_parent"
        android:background="@android:color/darker_gray"/>

    <TextView
        android:id="@+id/change_log_number_of_blocks"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:gravity="center_horizontal"
        android:maxLines="3"
        android:textSize="16sp"/>

    <View
        android:layout_width="0.5dp"
        android:layout_height="match_parent"
        android:background="@android:color/darker_gray"/>

    <TextView
        android:id="@+id/change_log_time"
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:gravity="center_horizontal"
        android:maxLines="3"
        android:textSize="16sp"/>

</TableRow>

<View
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="@android:color/darker_gray"/>
</TableLayout>

这是我在Java中设置我的recyclerView的地方。

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
mChangeLogRv.setLayoutManager(layoutManager);
mInventoryChangeLogAdapter = new InventoryChangeLogAdapter(null, mFlavorKeyAndName, this);
mChangeLogRv.setAdapter(mInventoryChangeLogAdapter);

任何帮助都将不胜感激。谢谢!

共有1个答案

齐成和
2023-03-14

将<code>再循环视图</code>和<code>主标题布局</code>放入<code>线性布局</code>中,并将该<code>非线性布局</code>置于<code>水平滚动视图</code>中。

<?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:layout_margin="5dp">

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

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

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="true">

            <TableRow>

                <TextView
                    android:id="@+id/change_log_flavor_name"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="4dp"
                    android:gravity="center_horizontal"
                    android:maxLines="3"
                    android:text="1"
                    android:textColor="@color/Black"
                    android:textStyle="bold"
                    android:textSize="16sp"/>

                <View
                    android:layout_width="0.5dp"
                    android:layout_height="match_parent"
                    android:background="@android:color/darker_gray"/>

                <TextView
                    android:id="@+id/change_log_batch_number"
                    android:layout_width="75dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="4dp"
                    android:gravity="center_horizontal"
                    android:maxLines="3"
                    android:text="2"
                    android:textColor="@color/Black"
                    android:textStyle="bold"
                    android:textSize="16sp"/>

                <View
                    android:layout_width="0.5dp"
                    android:layout_height="match_parent"
                    android:background="@android:color/darker_gray"/>


                <TextView
                    android:id="@+id/change_log_date"
                    android:layout_width="110dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="4dp"
                    android:gravity="center_horizontal"
                    android:maxLines="3"
                    android:text="3"
                    android:textColor="@color/Black"
                    android:textStyle="bold"
                    android:textSize="16sp"/>

                <View
                    android:layout_width="0.5dp"
                    android:layout_height="match_parent"
                    android:background="@android:color/darker_gray"/>

                <TextView
                    android:id="@+id/change_log_number_of_blocks"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="4dp"
                    android:gravity="center_horizontal"
                    android:maxLines="3"
                    android:text="4"
                    android:textColor="@color/Black"
                    android:textStyle="bold"
                    android:textSize="16sp"/>

                <View
                    android:layout_width="0.5dp"
                    android:layout_height="match_parent"
                    android:background="@android:color/darker_gray"/>

                <TextView
                    android:id="@+id/change_log_time"
                    android:layout_width="75dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="4dp"
                    android:gravity="center_horizontal"
                    android:maxLines="3"
                    android:text="5"
                    android:textColor="@color/Black"
                    android:textStyle="bold"
                    android:textSize="16sp"/>

                <View
                    android:layout_width="0.5dp"
                    android:layout_height="match_parent"
                    android:background="@android:color/darker_gray"/>

                <TextView
                    android:layout_width="75dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="4dp"
                    android:gravity="center_horizontal"
                    android:maxLines="3"
                    android:text="6"
                    android:textColor="@color/Black"
                    android:textStyle="bold"
                    android:textSize="16sp"/>

            </TableRow>

            <View
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@android:color/darker_gray"/>
        </TableLayout>


    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvOpsStatusList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbarStyle="outsideInset"
            android:scrollbars="horizontal" />

        </LinearLayout>

    </HorizontalScrollView>

    </LinearLayout>
 类似资料:
  • 我有一个水平回收视图。每个子级包含一个TextView和一个垂直RecyclerView。垂直RecyclerView的子级仅包含TextView。 垂直滚动非常平滑,但水平滚动滞后很多。我已经尝试在onBindViewHolder中使用swapAdapter,而不是setAdapter,但这并没有解决问题。我也尝试过更改数据集并调用notifyDataSetChanged(),但这也没有帮助。

  • 我正在使用GridView创建一个组件来创建像Excel这样的表。在这里,我最初创建了一个2x2网格,稍后当用户单击按钮时,会添加额外的行和列。 这是我添加新专栏的做法:- 这可以正常工作并添加额外的列。问题是当添加列时,以前的列会收缩以适应新列,从而使每次添加新列时列看起来更小。我想一次只在屏幕上显示2列,然后让用户水平向前滚动以查看更多列。现在网格只能垂直滚动。同样,我希望在添加新行时发生这种

  • 我正在使用下面的代码创建一个回收器视图。recyclerview有一个网格布局管理器,其项计数最多为每行2个。 不幸的是,我嵌套在ConstraintLayout中的回收器视图根本没有滚动。我错过了什么?约束布局是否支持相同的?

  • 好吧,这里你是下一篇关于固定页眉和页脚的无聊滚动表的文章。这个主题来自超文本标记语言的刚性结构。源问题是显示非常巨大的表格溢出屏幕宽度作为高度。我的愿望也是将标题固定在表格的顶部,因此将其副本固定在表格的底部。 在大量搜索和测试保证代码后,我发现了下一个深层嵌套问题:-页眉和页脚没有保持表体的单元格间距,而tbody是单独滚动的-tbody行覆盖了页眉-tbody的垂直滚动很难与整个表(包括页眉和

  • 我在一个大型遗留系统中工作,系统中有数千个页面,动态生成的表格数据被填充到html中,定义格式如下: 我的任务是移除不必要的小水平滚动条,这些滚动条似乎使系统感到困惑。经过一段时间的研究,我意识到当表格数据量垂直溢出包含的div并导致垂直滚动条出现时,新生成的垂直滚动条本身会推入div的内容区域,从而导致表格数据水平溢出,从而导致不希望出现的水平滚动条。换句话说,当垂直滚动条出现时,它会侵入内容空

  • 我在一个大型遗留系统中工作,系统中有数千个页面,动态生成的表格数据被填充到html中,定义格式如下: 我的任务是移除不必要的小水平滚动条,这些滚动条似乎使系统感到困惑。经过一段时间的研究,我意识到当表格数据量垂直溢出包含的div并导致垂直滚动条出现时,新生成的垂直滚动条本身会推入div的内容区域,从而导致表格数据水平溢出,从而导致不希望出现的水平滚动条。换句话说,当垂直滚动条出现时,它会侵入内容空