Gibt es eine Möglichkeit, zu stoppen, wenn die untere Blattlaibung aufhört, wenn der Benutzer den Finger hebt (MotionEvent.ACTION_UP). Was ich sehe, ist, dass das untere Blatt immer nach oben zeigt, um den gesamten Inhalt anzuzeigen.Wie kann man das Blättern auf dem unteren Blatt stoppen, wenn der Benutzer das Ziehen stoppt?
Ich habe eine benutzerdefinierte Bottom-Sheet-Verhalten implementiert, aber das scheint nicht den Trick zu tun. Hier ist der Code für das Verhalten des unteren Blattverhaltens Java.
import android.content.Context;
import android.graphics.Rect;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
public class LockableBottomSheetBehavior\<V extends View\> extends BottomSheetBehavior<V> {
public LockableBottomSheetBehavior() {}
public LockableBottomSheetBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
return super.onInterceptTouchEvent(parent, child, event);
}
@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
if(action == MotionEvent.ACTION_UP && getState() == BottomSheetBehavior.STATE_DRAGGING) {
Rect scrollBounds = new Rect();
child.getGlobalVisibleRect(scrollBounds); //Should we set height of
setState(BottomSheetBehavior.STATE_EXPANDED);
return true;
}
return super.onTouchEvent(parent, child, event);;
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, V child, View directTargetChild, View target, int nestedScrollAxes) {
return super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
}
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);
}
@Override
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) {
super.onStopNestedScroll(coordinatorLayout, child, target);
}
@Override
public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, V child, View target, float velocityX, float velocityY) {
return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
}
}`
Auch hier ist die Layout-Datei ich arbeite mit
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mayojava.sample.bottomsheetdemo.MainActivity">
<RelativeLayout
android:id="@+id/map_image_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<ImageView
android:id="@+id/map_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="@drawable/map"
/>
<Button
android:id="@+id/show_view_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="Show Bottom Sheet"/>
</RelativeLayout>
<ScrollView
android:id="@+id/layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_hideable="false"
app:behavior_peekHeight="400dp"
app:layout_behavior="com.snijsure.sample.bottomsheetdemo.LockableBottomSheetBehavior"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="@android:color/white"
android:orientation="vertical"
>
<TextView
android:id="@+id/title_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="@string/title1"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_curate_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title_text1"
android:clipToPadding="false"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:visibility="visible"/>
<TextView
android:id="@+id/title_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/recycler_curate_images"
android:text="@string/title2"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_curate_images_second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title_text2"
android:clipToPadding="false"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:visibility="visible"/>
</RelativeLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
In Ihrem onTouch-Ereignis stellen Sie den Status auf erweitert ein, dies könnte der mögliche Grund sein. Versuchen Sie, den Status auf Collapsed zu setzen. –
Hallo Nipun, Grund, warum ich den Status als EXPANDED setze ist, weil ich die Ansicht von unten "aufhören" möchte, um das Blatt größer zu machen. Das lässt mich jedoch denken, dass ich aufzeichnen sollte, was der Zustand war, als das "Ziehen" -Ereignis begann, d. H. Den Zustand in ACTION_DOWN aufzeichnete und in ACTION_UP in den entgegengesetzten Zustand überging. Ich werde das versuchen. –