首页 > 解决方案 > 垂直滑动布局内的水平滚动

问题描述

我有一个类似于导航抽屉的自定义视图类,但它是从下到上打开的。

在我的 XML 中,我有一个由这个自定义类包装的水平回收视图。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/video_cutter_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/videoview_bg"
    android:orientation="vertical"
    tools:ignore="RtlHardcoded">

    <RelativeLayout
        android:id="@+id/layout_surface_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/layout"
        android:background="@android:color/transparent"
        android:gravity="center"
        android:orientation="vertical">


        <com.devbrackets.android.exomedia.ui.widget.VideoView
            android:id="@+id/video_loader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" />


        <ImageView
            android:id="@+id/icon_video_play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@drawable/play_button"
            android:contentDescription="@null" />

    </RelativeLayout>


    <RelativeLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="72dp"
        android:background="?attr/video_timeline_bg">


        <RelativeLayout
            android:id="@+id/timeText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/textTimeStart"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginStart="7dp"
                android:layout_marginLeft="7dp"
                android:gravity="left"
                android:text="@string/timer2" />

            <TextView
                android:id="@+id/textTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:gravity="center"
                android:text="@string/timer2"
                android:textColor="?attr/color_accent" />

            <TextView
                android:id="@+id/textTimeEnd"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginEnd="7dp"
                android:layout_marginRight="7dp"
                android:layout_toEndOf="@+id/textTime"
                android:layout_toRightOf="@+id/textTime"
                android:gravity="right"
                android:text="@string/timer2" />

        </RelativeLayout>


        <androidx.appcompat.widget.AppCompatSeekBar
            android:id="@+id/handlerTop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:max="1000"
            android:paddingTop="30dp"
            android:progressDrawable="@android:color/transparent"
            android:secondaryProgress="0"
            android:thumb="@drawable/vector_apptheme_text_select_handle_middle" />


        <View
            android:id="@+id/lineTop"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@+id/handlerTop"
            android:background="@color/line_button" />


    </RelativeLayout>


    <SlidingLayer xmlns:slidingLayer="http://schemas.android.com/apk/res-auto"
        android:id="@+id/slider_panel"
        android:layout_width="match_parent"
        android:layout_height="400dip"
        android:layout_below="@+id/layout_surface_view"
        android:layout_gravity="bottom"
        android:gravity="bottom"
        slidingLayer:openLayer="false"
        slidingLayer:stickTo="bottom">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="400dip"
            android:background="@color/slider_panel_color_trans98">


            <TextView
                android:id="@+id/added_clips_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="7dp"
                android:padding="7dp"
                android:text="Selected 0 clips"
                android:textColor="?attr/text_color"
                android:textSize="@dimen/sp12"
                android:textStyle="bold" />

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/slider_iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_gravity="top|center"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:contentDescription="@null"
                android:padding="7dp"
                android:tint="?attr/color_accent"
                app:srcCompat="@drawable/vector_slide_down" />

            <Button
                android:id="@+id/btAdd"
                style="@style/BorderlessButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:gravity="center"
                android:shadowColor="?attr/textview_shadow"
                android:shadowDx="@integer/shadowDx"
                android:shadowDy="@integer/shadowDy"
                android:shadowRadius="@integer/shadowRadius"
                android:text="@string/add"
                android:textColor="?attr/color_accent"
                android:textSize="@dimen/sp14"
                android:textStyle="bold" />

            <Button
                android:id="@+id/btNext"
                style="@style/BorderlessButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/btAdd"
                android:gravity="center"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"
                android:shadowColor="?attr/textview_shadow"
                android:shadowDx="@integer/shadowDx"
                android:shadowDy="@integer/shadowDy"
                android:shadowRadius="@integer/shadowRadius"
                android:text="@string/next"
                android:textColor="?attr/color_accent"
                android:textSize="@dimen/sp14"
                android:textStyle="bold" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/mRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/btAdd"
                android:background="@color/slider_panel_color_trans98"
                android:scrollbarSize="@dimen/scrollbar_size"
                android:scrollbarStyle="outsideInset"
                android:scrollbarThumbHorizontal="?attr/color_accent"
                android:scrollbars="horizontal" />


        </RelativeLayout>

    </SlidingLayer>


</RelativeLayout>

所以我在垂直幻灯片(自定义视图)内有一个水平滚动(recyclerview )。

问题是这样的,请看下面的GIF文件:

垂直幻灯片内的水平滚动

如您所见,我无法在 recyclerview 中正确滚动。

你有什么建议吗?

标签: androidscrollviewhorizontal-scrollinghorizontalscrollviewvertical-scrolling

解决方案


SlidingLayer.java类内部onInterceptTouchEvent方法中添加以下代码以进行MotionEvent.ACTION_MOVE操作:

if (xDiff > yDiff) {
    return false;
}

它看起来像:

switch (action) {
    case MotionEvent.ACTION_MOVE:
        .
        .
        .

        if (xDiff > yDiff) {
            return false;
        }

        if (validHorizontalDrag || validVerticalDrag) {
            mIsDragging = true;
            setDrawingCacheEnabled(true);
        }

        break;

    .
    .
    .

推荐阅读