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

无对角线滚动垂直水平滚动视图->表格布局

锺英彦
2023-03-14

我在水平滚动视图中实现了一个表格布局,这也是垂直滚动视图的一部分。它是这样工作的;当垂直或水平滚动时,它会为每种滚动类型显式滚动。意思是当垂直滚动时,水平滚动根本不会发生,比如说,如果手指对角移动,就不会发生垂直或水平滚动。要水平滚动,必须再次触摸它,并且它只在水平方向滚动,如果手指对角移动,就不会发生垂直或水平滚动。[这里也是如此]。

一次手指触摸似乎只处理一次回调。我也需要对角线滚动,应该同时垂直和水平滚动,就像在iOS表格视图中一样。在所有6个方向滚动。

下面是代码

    <?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="horizontal">

        <ScrollView
            android:id="@+id/layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="5dip"
            android:scrollbars="none">

            <HorizontalScrollView
                android:id="@+id/horizontalView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dip"
                android:scrollbars="horizontal|vertical">

                <TableLayout
                    android:id="@+id/tlGridTable"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TableRow
                        android:id="@+id/row1"
                        android:layout_width="wrap_content"
                        android:layout_height="50dp">

                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                    </TableRow>
                    <TableRow
                        android:id="@+id/row1"
                        android:layout_width="wrap_content"
                        android:layout_height="50dp">

                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                    </TableRow>
                    <TableRow
                        android:id="@+id/row1"
                        android:layout_width="wrap_content"
                        android:layout_height="50dp">

                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                    </TableRow>
                   ---------------
----------------------
--------------------------
                    <TableRow
                        android:id="@+id/row1"
                        android:layout_width="wrap_content"
                        android:layout_height="50dp">

                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                        <ImageView
                            android:layout_width="100dp"
                            android:layout_height="match_parent"
                            android:src="@drawable/ic_launcher"
                            android:layout_margin="4dp"
                            android:background="@android:color/holo_green_light"/>
                    </TableRow>


                </TableLayout>
            </HorizontalScrollView>
        </ScrollView>
    </LinearLayout>

共有1个答案

弘涛
2023-03-14

我在这个链接上找到了答案:可能是同一个问题。

android中的垂直和水平滚动视图

   @Override
    public boolean onTouchEvent(MotionEvent event) {
        float curX, curY;

        switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                mx = event.getX();
                my = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                curX = event.getX();
                curY = event.getY();
                vScroll.scrollBy((int) (mx - curX), (int) (my - curY));
                hScroll.scrollBy((int) (mx - curX), (int) (my - curY));
                mx = curX;
                my = curY;
                break;
            case MotionEvent.ACTION_UP:
                curX = event.getX();
                curY = event.getY();
                vScroll.scrollBy((int) (mx - curX), (int) (my - curY));
                hScroll.scrollBy((int) (mx - curX), (int) (my - curY));
                break;
        }

        return true;
    }
 类似资料:
  • 所以我在垂直ScrollView中有一个水平回收器视图。我的布局中的所有内容都显示得很好,并且都按照我想要的方向滚动,并且它做得很好。 我唯一的问题是,RecyclerView位于ScrollView中其他内容的下方,当RecyclerViewer部分可见时,它会在启动时将RecyclerView的底部与屏幕的底部对齐。这意味着RecyclerView上方的内容被推离屏幕。 有谁知道为什么会发生这

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

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

  • 我有一个水平ScrollView,它有两个元素:CardView和水平RecycerView。所以,当用户水平滚动时,我希望这两个元素滚动。 我想有这样的东西:Goal,橙色的线是CardView,黄色的线是RecycerView。当用户滚动时,两个元素滚动,如下所示:Scrolled Goal。 现在在我的应用程序中,当用户滚动时,只有RecycerView滚动。CardView保持在他的位置。

  • 问题内容: 如标题中所述,我一直在尝试通过水平滚动设置某种垂直流布局。布局中的组件将是JLabels。让我画一幅画: 同一窗口,垂直扩展 因此,标签将填充可用的垂直空间,然后创建一个新列。一旦可用的水平空间用尽,就会出现一个 水平 滚动条。 垂直滚动条通常不应出现;但是,如果窗口的垂直高度异常小,最好有一个垂直滚动条。 任何帮助是极大的赞赏。我是Java的新手,所以任何其他解释都将是很棒的。谢谢!

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