0

我的问题是,在代码中创建 TableLayout 之后,我将它添加到活动视图中,我真的需要它是可滚动的。该表是从包含 SQL 查询结果的结果集中创建的,它可能会根据查询本身而有所不同,因此它必须是“通用的”,而不总是可滚动的。我在stackoverflow上找到了类似滚动问题的答案,经过一番阅读,我建立了这样的活动:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:clickable="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideOverlay"
android:scrollbars="horizontal|vertical"
android:visibility="visible"
tools:context=".Wyswietlanie" >

<RelativeLayout
android:id="@+id/rel1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
 >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="23dp"
    android:text="@string/wczytywanie"
    android:textAppearance="?android:attr/textAppearanceLarge" />





</RelativeLayout>
</ScrollView>

在代码中,我只是像这样添加我生成的 TableLayout:

rl1.addView(result);

其中 rl1 是相对布局(通过 id 找到),结果是 TableLayout。TableLayout 显示自己,但没有什么是可滚动的。没有可见的滚动条,当我在不同方向上滑动手指时没有任何反应。什么都没有。我的错误在哪里?我应该使用其他东西吗?

(请忽略显然生成的表格布局与文本视图重叠的事实,我将其保存以备后用。)

4

1 回答 1

0

尝试将滚动视图的布局宽度更改为 match_parent。

android:layout_width="match_parent"
android:layout_height="match_parent"
于 2013-08-15T13:17:55.233 回答