我创建了一个具有底纸行为的活动。我在这里共享布局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>
实施后,我可以通过触摸折叠底部的表并拖动此布局中的任何视图。但是,我想通过在布局中拖动视频视图(mainMediaFrame)来关闭工作表。也就是说,我不想通过向下滚动嵌套的滚动视图来关闭最底页。我该如何实现?
答案 0 :(得分:0)
如果用户触摸VideoView
,以下解决方案将不会拖动底页。
概念很简单
在您的活动中
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);
}
}
答案 1 :(得分:0)
您尝试过吗:
service apache2 status
service apache2 start
答案 2 :(得分:0)
private class ScrollTouchListener implements View.OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mVideoDetailsView.setNestedScrollingEnabled(true);
activityLockBehavior.setAllowUserDragging(false);
break;
case MotionEvent.ACTION_MOVE:
mVideoDetailsView.setNestedScrollingEnabled(true);
activityLockBehavior.setAllowUserDragging(false);
break;
case MotionEvent.ACTION_UP:
mVideoDetailsView.setNestedScrollingEnabled(false);
activityLockBehavior.setAllowUserDragging(true);
break;
}
return false;
}
}
将此滚动侦听器添加到嵌套的scrollview
mNestedScrollView.setOnTouchListener(new ScrollTouchListener());