TableLayout不在ScrollView中滚动

时间:2013-08-15 13:13:34

标签: android scrollview tablelayout

我的问题是在我在代码中创建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显示自身,但没有任何内容可滚动。没有滚动条可见,当我在不同方向上滑动手指时没有任何反应。什么都没有。我的错误在哪里?我应该用别的吗?

(请忽略显然生成的tablelayout与textview重叠的事实,我将其保存以供日后使用。)

1 个答案:

答案 0 :(得分:0)

尝试将scrollview的布局宽度更改为match_parent。

android:layout_width="match_parent"
android:layout_height="match_parent"
相关问题