user1417127
user1417127

Reputation: 1645

Android how to prevent scrollview's content jump when resize scrollview?

I have a layout like this:

<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>

When I scroll the ScrollView to top of the screen, I will hide the TableRow inside ScrollView and show the TableRow outside by calling

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

That will make the TableRow outside ScrollView always on top of the screen. It works fine except when TableRow inside is hiding, all contents inside ScrollView will be pushed up a bit (equal the height of TableRow). I don't want it jump up like that because scroll action will not look smooth. Is there anyway to prevent the ScrollView contents auto fill the blank space like that?

Upvotes: 2

Views: 1577

Answers (1)

Carnal
Carnal

Reputation: 22064

When you use setVisibility(View.GONE); It will be completely removed, what you want to do in order to leave the empty space there, is to use setVisibility(View.INVISIBLE);

Upvotes: 2

Related Questions