[英]How to make a horizontally scrollable TableLayout?
I have a scrollable view / layout with a constraint layout in it.我有一个带有约束布局的可滚动视图/布局。
Inside of this layout I have a lot of other stuff.在这个布局里面,我还有很多其他的东西。 On the bottom of the layout I need a Tablelayout which I create programatically.在布局的底部,我需要一个以编程方式创建的 Tablelayout。
How can I make this TableLayout scrollable horizontally?如何使此 TableLayout 可水平滚动?
<ScrollView
android:id="@+id/testlay"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="5dip"
android:layout_marginStart="60dp"
android:fillViewport="false"
android:scrollbarStyle="outsideInset"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayoutProductTableHeader">
<TableLayout
android:id="@+id/linearLayoutProductTable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:isScrollContainer="true"
android:stretchColumns="*"
tools:ignore="MissingConstraints">
</TableLayout>
</ScrollView>
I tried to use a HorizontalLayout inside the ScrollView too but it doesnt work.我也尝试在 ScrollView 中使用 HorizontalLayout 但它不起作用。
This is how I implemented it and works for me:这就是我实现它并为我工作的方式:
<?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="vertical" >
<ScrollView
android:id="@+id/layout"
android:layout_height="match_parent"
android:scrollbars="horizontal|vertical"
android:layout_width="match_parent"
android:layout_marginTop="5dip"
android:scrollbarStyle="outsideInset"
android:fillViewport="true">
<HorizontalScrollView
android:id="@+id/horizontalView"
android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical"
android:layout_width="wrap_content"
android:layout_marginTop="5dip">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tlGridTable" >
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
好的,我认为问题是因为我以编程方式添加了表格行和列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.