【发布时间】:2021-03-30 10:12:03
【问题描述】:
ScrollView 和 HorizontalScroll 在垂直或水平滚动时截断一些元素
这是我的 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>
这里是动态添加视图到horizontalScrollview
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"