代码之家  ›  专栏  ›  技术社区  ›  Abhishek A Udupa

坐标布局底部的RecyclerView滚动条

  •  0
  • Abhishek A Udupa  · 技术社区  · 5 年前

    Coordinatorlayout ConstraintLayout 具有 BottomSheetBehavior .

        <?xml version="1.0" encoding="utf-8"?>
    <layout 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">
    
        <data>
    
            <variable
                name="..."
                type="..." />
        </data>
    
        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/appbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:elevation="0dp">
    
                <com.google.android.material.appbar.MaterialToolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:gravity="center_vertical"
                    app:title="..."
                    app:titleTextAppearance="@style/titleStyle"
                    app:titleTextColor="@android:color/white" />
    
                <com.google.android.material.tabs.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/colorPrimary"
                    app:tabIndicatorColor="@color/colorSecondary"
                    app:tabMode="scrollable"
                    app:tabRippleColor="@null"
                    app:tabTextAppearance="@style/textStyleCaption"
                    app:tabTextColor="@color/colorOnPrimary" />
    
            </com.google.android.material.appbar.AppBarLayout>
    
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/viewPager_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorPrimary"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                tools:ignore="KeyboardInaccessibleWidget">
    
                <androidx.viewpager2.widget.ViewPager2
                    android:id="@+id/viewPager"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
            </androidx.constraintlayout.widget.ConstraintLayout>
    
            <TextView
                android:id="@+id/scrim"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#aa000000"
                android:visibility="gone" />
    
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/foreground"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/top_rounded_corner"
                android:orientation="vertical"
                app:behavior_peekHeight="56dp"
                app:layout_behavior=".util.GestureLockedBottomSheetBehavior">
    
                <TextView
                    android:id="@+id/inventory_summary_header"
                    style="@style/textStyleButton"
                    android:layout_width="match_parent"
                    android:layout_height="56dp"
                    android:background="@drawable/top_rounded_corner"
                    android:drawableEnd="@drawable/ic_arrow_drop_up_black_24dp"
                    android:drawableRight="@drawable/ic_arrow_drop_up_black_24dp"
                    android:elevation="4dp"
                    android:gravity="center_vertical"
                    android:padding="@dimen/verticalMargin"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:targetApi="lollipop" />
    
                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/selected_items_list"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:overScrollMode="never"
                    android:visibility="gone"
                    app:layout_constraintBottom_toTopOf="@id/continue_button"
                    app:layout_constraintTop_toBottomOf="@id/inventory_summary_header" />
    
                <TextView
                    android:id="@+id/no_items_added"
                    style="@style/textStyleHeadline"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_gravity="center"
                    android:drawableStart="@drawable/ic_warning_black_24dp"
                    android:drawableLeft="@drawable/ic_warning_black_24dp"
                    android:gravity="center"
                    android:text="..."
                    android:visibility="visible"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/inventory_summary_header" />
    
                <com.google.android.material.button.MaterialButton
                    android:id="@+id/continue_button"
                    style="@style/filledButtonStyle2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/verticalMargin"
                    android:layout_marginRight="@dimen/verticalMargin"
                    android:text="@string/continue_text"
                    app:layout_constraintBottom_toBottomOf="parent" />
    
            </androidx.constraintlayout.widget.ConstraintLayout>
    
            <ProgressBar
                android:id="@+id/progress_indicator"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorOnPrimary"
                android:padding="180dp"
                android:visibility="gone" />
    
        </androidx.coordinatorlayout.widget.CoordinatorLayout>
    </layout>
    

    这是我的建议 GestureLockedBottomSheetBehavior

    class GestureLockedBottomSheetBehavior<V : View>(context: Context, attributeSet: AttributeSet) :
        BottomSheetBehavior<V>(context, attributeSet) {
    
        override fun onInterceptTouchEvent(
            parent: CoordinatorLayout,
            child: V,
            event: MotionEvent
        ): Boolean {
            return false
        }
    
        override fun onStartNestedScroll(
            coordinatorLayout: CoordinatorLayout,
            child: V,
            directTargetChild: View,
            target: View,
            axes: Int,
            type: Int
        ): Boolean {
            return false
        }
    }
    

    用这个我的 RecyclerView STATE_EXPANDED 回收视图 STATE_HALF_EXPANDED .

    如果有人知道如何解决这个问题,那将非常有帮助。

    0 回复  |  直到 5 年前