이 비디오를보고 내가 무슨 말을하는지 알 수 있습니다. BottomSheet
뒤에있을 때도 어떻게 끌 수 있는지 확인 하십시오 BottomNavigationView
.
나는 같은 일을하고 싶어하지만 함께 LinearLayout
포함하는 Button
대신이야. 나는 많은 것을 시도했지만 아무것도 작동하지 않았습니다. 을 LinearLayout
재정의 할 수 있도록 서브 클래 싱 했으며 스크롤을 감지하기 onInterceptTouchEvent
위해 GestureListener
를 사용하고 있습니다.
Github에 베어 본 테스트 프로젝트를 게시했습니다.
https://github.com/gavingt/BottomSheetTest
또는 아래 관련 코드를 확인할 수 있습니다.
여기 있습니다 MyLinearLayout
:
public class MyLinearLayout extends LinearLayout {
GestureDetector gestureDetector;
boolean isScrolling = false;
public MyLinearLayout(Context context) {
super(context);
gestureDetector = new GestureDetector(context, new MyGestureListener());
}
public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
gestureDetector = new GestureDetector(context, new MyGestureListener());
}
public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
gestureDetector = new GestureDetector(context, new MyGestureListener());
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
gestureDetector.onTouchEvent(ev);
return isScrolling;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
isScrolling = gestureDetector.onTouchEvent(ev);
return isScrolling;
}
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
Log.i("TAG", "onScroll: ");
return true;
}
}
}
그리고 여기 있습니다 activity_main.xml
:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F00"
android:overScrollMode="never"
app:behavior_hideable="false"
app:behavior_peekHeight="262dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"/>
<com.gavinsappcreations.bottomsheettest.MyLinearLayout
android:layout_gravity="bottom"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/first_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:drawableLeft="@android:drawable/btn_radio"
android:drawablePadding="2dp"
android:maxLines="1"
android:backgroundTint="#00F"
android:paddingLeft="9dp"
android:paddingRight="10dp"
android:text="first button"
android:textAllCaps="false"
android:textSize="17dp"/>
<Button
android:id="@+id/second_button"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginLeft="50dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:backgroundTint="#00F"
android:drawablePadding="2dp"
android:drawableRight="@android:drawable/btn_radio"
android:maxLines="1"
android:paddingLeft="8dp"
android:paddingRight="5dp"
android:text="second button"
android:textAllCaps="false"
android:textSize="16dp"/>
</com.gavinsappcreations.bottomsheettest.MyLinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Reddit 사용자 덕분에이 문제를 해결했습니다 .
해결책은 그의 DelegatingLayout을 사용하는 것이 었습니다.
https://gist.github.com/davidliu/c246a717f00494a6ad237a592a3cea4f
전체 구현은 Github 프로젝트를 참조하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다