![](/img/trans.png)
[英]add ScrollView and HorizontalScrollView to a TableLayout
[英]ScrollView+HorizontalScrollView+Scale is not properly scroll
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);
將根布局更改為 NestedScrollView。
基本上,您的 ScrollView 和 HorizontalScrollView 的滾動屬性是重疊的,而 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 的更多信息,請查看文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.