Tanuj Wadhwa
Tanuj Wadhwa

Reputation: 2045

ViewFlipper inside scroll view in android

I have a view flipper whose content exceeds the screen size, so I placed it inside a ScrollView. But after doing so, the view flipper's OnTouchEvent doesn't work, since the scroll gesture is handled by the ScrollView.

I want the scroll view to handle the scroll but also allow its child(ViewFlipper) to handle the scoll event. How can I accomplish this.

This is the code for flipper and the scroll view:

<ScrollView
    android:id="@+id/scroll"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
        <ViewFlipper
            android:id="@+id/flipperDetails"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"></ViewFlipper>
</ScrollView>

Upvotes: 2

Views: 1504

Answers (1)

Yuraj
Yuraj

Reputation: 3195

I am using similiar code for nested viewpager, this should work for scrollview too:

public class NestedScrollView extends ScrollView {

public NestedScrollView(Context context) {
    super(context);
}

public NestedScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v != this && v instanceof ViewFlipper) {
       return true;
    }
    return super.canScroll(v, checkV, dx, x, y);
}
}

Also change ScrollView in xml to NestedScrollView.

EDIT:

canScroll

Tests scrollability within child views of v given a delta of dx.

Return true if child views of v can be scrolled by delta of dx.

Upvotes: 1

Related Questions