gpt4 book ai didi

android - 限制 Bottom Sheet 向下滑动

转载 作者:行者123 更新时间:2023-12-03 10:12:15 25 4
gpt4 key购买 nike

我创建了一个具有 Bottom Sheet 行为的 Activity 。我在这里分享布局 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_details_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor"
app:behavior_hideable="true"
app:behavior_peekHeight="@dimen/player_sheet_peek_height"
app:layout_behavior="@string/bottom_sheet_behavior">

<LinearLayout
android:id="@+id/detailsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:id="@+id/mainMediaFrame"
android:layout_width="match_parent"
android:layout_height="@dimen/zero_dimen"
android:layout_weight="0.35"
android:background="@android:color/black">

<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/exoPlayerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
app:resize_mode="fit"
app:surface_type="texture_view" />


</FrameLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/videoScroller"
style="@style/scrollBarStyle"
android:layout_height="@dimen/zero_dimen"
android:layout_weight="0.65"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<!--todo:include scroll view content layout-->

</android.support.v4.widget.NestedScrollView>
</LinearLayout>

</RelativeLayout>

实现后,我可以通过触摸折叠 Bottom Sheet 并拖动此布局中的任何 View 。但是,我想通过在布局中拖动视频 View (mainMediaFrame)来关闭工作表。也就是说,我不想通过向下滚动嵌套 ScrollView 来关闭 Bottom Sheet 。我怎样才能做到这一点?

最佳答案

如果用户触摸 VideoView,以下解决方案将不会拖动 Bottom Sheet .

概念很简单

  • 禁用 VideoView 的触摸
  • 用户触摸 VideoView 时禁用拖动

  • 在您的 Activity 中
    final LockBottomSheetBehaviour behavior = (LockBottomSheetBehaviour) LockBottomSheetBehaviour.from(bottomSheet);
    findViewById(R.id.videoView).setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    behavior.setAllowUserDragging(false);
    break;
    case MotionEvent.ACTION_UP:
    behavior.setAllowUserDragging(true);
    break;
    }
    return true;
    }
    });

    在布局中替换
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"


    app:layout_behavior="com.package.LockBottomSheetBehaviour"

    LockBottomSheetBehaviour.class
    import android.content.Context;
    import android.support.design.widget.BottomSheetBehavior;
    import android.support.design.widget.CoordinatorLayout;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.view.View;

    public class LockBottomSheetBehaviour<V extends View> extends BottomSheetBehavior<V> {
    private boolean mAllowUserDragging = true;

    public LockBottomSheetBehaviour() {
    super();
    }

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

    public void setAllowUserDragging(boolean allowUserDragging) {
    mAllowUserDragging = allowUserDragging;
    }

    @Override
    public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!mAllowUserDragging) {
    return false;
    }
    return super.onInterceptTouchEvent(parent, child, event);
    }
    }

    关于android - 限制 Bottom Sheet 向下滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52443138/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com