views:

151

answers:

1

I have a ScrolLView that wraps a ViewFlipper. The content in the ViewFlipper is not of equal height, so my second screen has a very long scrollbar that goes on and on with blank content:

<ScrollView android:id="@+id/outer_scroll"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true">
<ViewFlipper android:id="@+id/flipper"
android:layout_width="fill_parent" android:layout_height="fill_parent">

<EditText android:id="@+id/desc" style="@style/DescriptionArea"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:enabled="false" android:focusableInTouchMode="false"
android:background="@null" />

<LinearLayout android:id="@+id/details_root"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="10dp">

<TextView android:id="@+id/item_details" style="@style/DetailsLarge"
android:textColor="#000" android:visibility="gone"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:text="@string/item_details_tags" />
<TextView android:id="@+id/tags" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textColor="#000"
android:visibility="gone" />
</LinearLayout>
</ViewFlipper>
</ScrollView>

So, for example, the EditText block is very long, and the scroll bar captures it all. I fling to the LinearLayout, and the scrollbar continues way past the TextView content. I essentially need it to "recalculate" the view height.

Also, wrapping the EditText and LinearLayout within their own ScrollViews is not an option, because then the soft/virtual keyboard blocks the EditText content.

+2  A: 

During measure, ViewFlipper (as well as ViewSwitcher, TextSwitcher etc. - all descendants of ViewAnimator) will by default be sized according to the largest child, including the non-visible ones.

Set the MeasureAllChildren flag to false to change this behavior to only use the currently visible child when measuring the size:

ViewFlipper flipper = (ViewFlipper)findViewById(R.id.flipper);
flipper.setMeasureAllChildren(false);
Thorstenvv