捏以在滚动视图中使用寻呼机进行缩放(类似于instagram所做的操作)

时间:2019-03-04 09:54:56

标签: android android-viewpager imageview android-scrollview pinchzoom

我正在使用https://github.com/MikeOrtiz/TouchImageView缩放Imageview,将Viewpager扩展为覆盖canScroll方法。翻页器的效果很好,但是捏缩放手势无法正常工作。这种滚动而不是缩放图像。

public class HeightWrappingPager extends ViewPager{

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

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

        @Override
        protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
            if (v instanceof TouchImageView) {
                return ((TouchImageView) v).canScrollHorizontallyFroyo(-dx);
            } else {
                return super.canScroll(v, checkV, dx, x, y);
            }
        }
    }

这是我的观点

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.custom_ui.ZoomableImageView
            android:id="@+id/post_image"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </android.support.constraint.ConstraintLayout>

这是我的父视图

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="40dp"
    android:clipToPadding="false"
    android:paddingBottom="50dp"
    android:scrollbars="vertical"
    app:layout_constraintTop_toBottomOf="@id/toolbar">

    <com.custom_ui.HeightWrappingPager
        android:id="@+id/post_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/five_dp"
        android:background="@color/white_transparent"
        android:minHeight="50dp"
        app:layout_constraintTop_toBottomOf="@id/post_description" />

    <LinearLayout
        android:id="@+id/layoutDots"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintTop_toBottomOf="@id/post_list" />
</ScrollView>

0 个答案:

没有答案