【问题标题】:ScrollView+HorizontalScrollView+Scale is not properly scrollScrollView+Horizo​​ntalScrollView+Scale 不能正确滚动
【发布时间】:2021-03-30 10:12:03
【问题描述】:

ScrollView 和 Horizo​​ntalScroll 在垂直或水平滚动时截断一些元素

这是我的 xml 布局

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainScrollView"
    android:fillViewport="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <HorizontalScrollView
        android:id="@+id/horizontalScroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</ScrollView>

这里是动态添加视图到horizo​​ntalScrollview

TableLayout table = new TableLayout(this);
        for (int i = 0; i < 50; i++) {
            TableRow row = new TableRow(this);
            for (int j = 0; j < 20; j++) {
                TextView cell = new TextView(this);
                cell.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.black_square_border, null));

                cell.setText(("(" + i + ", " + j + ")"));
                cell.setTextSize(10f);
                //  cell.setPadding(6,6,6,6);
                textViewList.add(cell);
                row.addView(cell);
            }
            table.addView(row);
        }

        horizontalScroll.addView(table);

【问题讨论】:

  • 尽可能添加 xml 和任何屏幕截图
  • 尝试在线性布局中使用 TableLayout
  • @Usama 无法解决
  • 我不建议将滚动视图放在另一个滚动视图中。尝试添加 android:nestedScrollingEnabled="true"

标签: java android


【解决方案1】:

将根布局更改为 NestedScrollView。

基本上,您的 ScrollView 和 Horizo​​ntalScrollView 的滚动属性是重叠的,而 NestedScrollView 旨在解决此问题。您的布局可能如下所示:

<NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainScrollView"
    android:fillViewport="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <HorizontalScrollView
        android:id="@+id/horizontalScroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</NestedScrollView>

要了解有关 NestedScrollViews 的更多信息,请查看the documentation

【讨论】:

  • 滚动时仍然剪切一些内容
  • 这个新问题与您的行有关。根据您希望视图的显示方式将layoutParams 添加到您的行中。
  • 呈现相同的问题
  • 其实我想放大或缩小视图与适当的两侧滚动,如果有任何指南请提及它是如何完成的,谢谢
  • 缩放或滚动?请注意,这是两个非常不同的操作。
猜你喜欢
  • 2018-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多