Android如何在调整scrollview时阻止scrollview的内容跳转?

时间:2012-07-09 07:39:21

标签: android scrollview

我有这样的布局:

<TableRow
        android:id="@+id/TabHidden"
        android:layout_width="fill_parent"
        android:layout_height="45dp"
        android:background="@drawable/bg_detail_tab1"
        android:paddingLeft="5dip"
        android:paddingRight="5dip"
        android:paddingTop="10dip"
        android:visibility="gone"
    >
        ...
</TableRow>
<ScrollView
    android:id="@+id/ScrollViewGameDetail"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:fillViewport="true" >
    <TableRow
        android:id="@+id/Tab"
        android:layout_width="fill_parent"
        android:layout_height="45dp"
        android:background="@drawable/bg_detail_tab1"
        android:paddingLeft="5dip"
        android:paddingRight="5dip"
        android:paddingTop="10dip"
    >
        ...
    </TableRow>
    ...
</ScrollView>

当我将ScrollView滚动到屏幕顶部时,我将隐藏ScrollView中的TableRow并通过调用

显示TableRow
tabHidden.setVisibility(TableRow.VISIBLE);
tab.setVisibility(TableRow.GONE);

这将使ScrollView外的TableRow始终位于屏幕顶部。它工作正常,除非TableRow里面隐藏,ScrollView中的所有内容都会被推高一点(等于TableRow的高度)。我不希望它像那样跳起来,因为滚动动作看起来不会很平滑。反正有没有阻止ScrollView内容自动填充这样的空白区域?

1 个答案:

答案 0 :(得分:1)

当您使用setVisibility(View.GONE);它将被完全删除,您想要做的是为了留空空间,是使用setVisibility(View.INVISIBLE);