标签: bottom-sheet

如何防止 M3 Compose ModalBottomSheet 在抛出内部 LazyRow 内容时分离?

我有一个ModalBottomSheet,里面有一个LazyColumn项目列表。当我快速向上或向下滚动(即快速滚动)该LazyColumn内容时,底部工作表会短暂地从底部或顶部分离(取决于滚动方向)。我想删除这种行为,以便我的ModalBottomSheet牢牢地粘在底部和顶部(它是全屏底部工作表)。

有谁知道如何实现这一目标?:)

我正在使用此依赖项中当前最新的底表: androidx.compose.material3:material3-android:1.2.0-alpha02

它是这样的: 在此输入图像描述

我删除了很多内容代码,但一般来说底部工作表内容是这样的:

@Composable
fun BottomSheetContent() {
    Column(modifier = modifier.fillMaxSize()) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .padding(horizontal = 16.dp)
                .verticalScroll(rememberScrollState())
                .weight(1f)
        ) {
            GenresSection(
                selectedGenres = selectedGenres,
            )
            
        }
        ResetAllAndApplyFilterButtonsRow(
            modifier = Modifier
                .fillMaxWidth()
                .padding(vertical = 16.dp, horizontal = 16.dp)
        )
    }
}

@Composable
fun GenresSection(
    selectedGenres: List<Genre>,
    modifier: Modifier = Modifier,
) {
    LazyColumn(
        modifier = modifier.height(400.dp),
    ) {
        items(selectedGenres) { genre ->
            GenreChoiceRow(
                text = genre.name,
                modifier …
Run Code Online (Sandbox Code Playgroud)

android bottom-sheet android-jetpack-compose

5
推荐指数
1
解决办法
780
查看次数

如何保持列表最后一项在bottomsheeet之上

我正在建立一个音乐播放器.我正在努力bottomsheet.它的工作正常,它有它的窥视高度,但它涵盖了RecyclerView的最后一项.如何设置recyclerView上方BottomSheet视图.请帮我.

这是我的MainActivity XML

<?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:id="@+id/tab_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/orange"
            app:tabIndicatorColor="@color/colorAccent"
            app:tabIndicatorHeight="3dp"
            app:tabMode="fixed"
            app:tabTextColor="@color/white" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <!-- View useed to load other fragments so that my Bottomsheet can be seen above other fragments -->
    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    <!-- BottomSheet layout-->
    <FrameLayout
        android:id="@+id/framelayouts"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="8dp"
        android:clickable="true"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <include …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-recyclerview bottom-sheet

4
推荐指数
1
解决办法
526
查看次数

FAB 隐藏在底部工作表下

我有以下 XML:

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/app_bar">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <fragment
            android:id="@+id/fragment1"
            android:name="com.xyz.Fragment1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            tools:layout="@layout/fragment_layout1" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layoutBottomSheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="@dimen/global_margin"
        android:orientation="vertical"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <fragment
            android:id="@+id/fragment2"
            android:name="com.xyz.Fragment2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center|top"
            tools:layout="@layout/fragment_layout2" />
    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/global_margin"
        android:layout_marginRight="@dimen/global_margin"
        android:src="@drawable/ic_add_white_24dp"
        app:borderWidth="0dp"
        app:elevation="4dp"
        app:layout_anchor="@id/layoutBottomSheet"
        app:layout_anchorGravity="top|right|end" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

布局应该出现,Fragment1然后低于Fragment2和FAB锚定到Fragment2但是,上面 Fragment2而不是它。

实际上它显示为,

截屏

出了什么问题?任何的想法?

android floating-action-button bottom-sheet

4
推荐指数
1
解决办法
3986
查看次数

AS找不到BottomSheetBehavior_Params,_behavior_peekHeight和_behavior_hideable

我只是将我的应用程序更新为支持库版本24.0.0,我收到一些关于BottomSheet Params的错误.
代码:

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.
 * @param attrs   The {@link AttributeSet}.
 */
public BottomSheetBehaviorGoogleMapsLike(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.BottomSheetBehavior_Params);
    setPeekHeight(a.getDimensionPixelSize(
            android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_peekHeight, 0));
    setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_hideable, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
Run Code Online (Sandbox Code Playgroud)

Android Studio找不到:

  • android.support.design.R.styleable.BottomSheetBehavior_Params
  • android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_peekHeight
  • android.support.design.R.styleable.BottomSheetBehavior_Params_behavior_hideable

知道他们搬到哪里了吗?

android android-support-library android-studio android-layoutparams bottom-sheet

4
推荐指数
1
解决办法
759
查看次数

如何实现具有固定高度的BottomSheetDialogFragment

我需要实施BottomSheetDialogFragment并面对问题.我需要我BottomSheetDialogFragment有固定的高度.有谁知道怎么做?

这是我的片段内容的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/bottom_sheet_height"
    android:background="@android:color/white"
    android:orientation="vertical">

    <TextView
        android:id="@+id/drag_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24sp"
        android:textColor="#FF0000"
        android:text="Title"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@android:color/white"
        android:layout_weight="1"/>

    <TextView
        android:id="@+id/ok_button"
        android:layout_width="match_parent"
        android:layout_height="54dp"
        android:background="@android:color/holo_blue_dark"
        android:gravity="center"
        android:text="Hello"
        android:textColor="@android:color/white"
        android:textSize="24sp"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

setupDialog()我这样做:

@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);
    View contentView = View.inflate(getContext(), R.layout.bottom_sheet_dialog_content_view, null);
    dialog.setContentView(contentView);
    CoordinatorLayout.LayoutParams layoutParams = ((CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams());
    CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
    if (behavior != null && behavior instanceof BottomSheetBehavior) {
        ((BottomSheetBehavior) behavior).setBottomSheetCallback(bottomSheetCallback);
        ((BottomSheetBehavior) behavior).setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_height));
    } …
Run Code Online (Sandbox Code Playgroud)

android behavior bottom-sheet

4
推荐指数
1
解决办法
1万
查看次数

java.lang.IllegalArgumentException:视图与BottomSheetBehavior无关

我知道之前已经问过,但即使我检查了答案,我也没有找到解决我具体问题的方法:

我创建了一个预期充当底层的布局:

<android.support.constraint.ConstraintLayout 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/btmsht"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:orientation="vertical"
android:layout_height= "300dp"
android:layout_width="match_parent"
tools:showIn="@layout/activity_principal">
Run Code Online (Sandbox Code Playgroud)

我在协调器布局中使用它:

<include layout="@layout/btmsht_principal" android:layout_width="match_parent"
    android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试获取参考时:

View tview = findViewById(R.id.btmsht);
    btmsht = BottomSheetBehavior.from(tview);
Run Code Online (Sandbox Code Playgroud)

我收到错误:

java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior
        at android.support.design.widget.BottomSheetBehavior.from(BottomSheetBehavior.java:816)
        at com.blixter.fiesta.Principal.creacionViews(Principal.java:69)
        at com.blixter.fiesta.Principal.onCreate(Principal.java:57)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at …
Run Code Online (Sandbox Code Playgroud)

android bottom-sheet

4
推荐指数
1
解决办法
4899
查看次数

如何向BottomSheetDialogFragment添加动画

我有一个BottomSheetDialogFragment,其中有两个按钮,当我点击任何按钮时,会调用dismiss()方法.有没有办法让BottomSheetDialogFragment动画化.我想让它显示一个持续时间为1000毫秒的慢速滑动动画.

示例代码

   signin.findViewById(R.id.signin_button_using).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            callback.onClickSignInEmail();
            dismiss();
        }
    })
Run Code Online (Sandbox Code Playgroud)

android android-animation bottom-sheet

4
推荐指数
1
解决办法
3565
查看次数

禁用带有可滚动子项的BottomSheetDialogFragment的拖动

是否可以禁用对BottomSheetDialogFragment包含可滚动视图(例如a ViewPager或a)的a的NestedScrollView拖动,以使其既不能向上或向下拖动,但仍可以通过触摸外部而关闭,并且无论如何都可以拖动子级?

我在这里查看了所有答案但我不满意,因为大多数人没有考虑可滚动的子项或通过强制展开状态来工作。最接近的是这个答案,但是仍然允许将工作表向上拖动。

在我应修改原始源代码方面,是否有任何解决方案或至少是指南?

android bottom-sheet

4
推荐指数
1
解决办法
2424
查看次数

Side-Swipeable Gallery of BottomSheets?

我正在尝试在Android中实现与下图类似的摘要底页库.是否有任何方法可以将多个底部纸张连接到一个视图,您可以向左/向右滑动以切换并让相邻视图从屏幕的垂直边缘窥视?

底部图库示例 谢谢!

layout android view android-layout bottom-sheet

4
推荐指数
1
解决办法
378
查看次数

在BottomSheetDialogFragment内部添加/替换片段

此代码:在其中我要添加片段的地方打开bottomSheetDialogFragment。

我想在bottomsheetDialogFragment中添加多个片段,但是会抛出

java.lang.IllegalArgumentException:找不到ID为0x7f0a01cb的视图

class AddNotesBottomSheetDialog : BottomSheetDialogFragment() {

private lateinit var bottomSheetDialog: BottomSheetDialog
private lateinit var bottomSheetBehavior: BottomSheetBehavior<View>

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    Log.v(LOG_TAG, "-> onCreateDialog")

    bottomSheetDialog = BottomSheetDialog(context!!)

    var view = View.inflate(context, R.layout.bottom_sheet_notes, null)
    bindViews(view)
    bottomSheetDialog.setContentView(view)
    bottomSheetBehavior = BottomSheetBehavior.from(view.parent as View)
    bottomSheetBehavior.isHideable = false
    bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED

    return bottomSheetDialog
}

private fun bindViews(view: View) {
    loadAddNotesFragments()

}

override fun onStart() {
    super.onStart()
    Log.v(LOG_TAG, "-> onStart")

    bottomSheetBehavior.isHideable = false
    bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
    if (!visible)
        dialog.hide()
}


fun show(fragmentManager: FragmentManager) …
Run Code Online (Sandbox Code Playgroud)

android android-xml bottom-sheet

4
推荐指数
1
解决办法
1877
查看次数