标签: bottom-sheet

BottomSheetDialogFragment 不断重新出现在 onResume 处

我使用以下代码显示 BottomSheetDialogFragment:

BottomSheetDialogFragment bottomSheetDialogFragment = new MediaAddFragment();
    bottomSheetDialogFragment.show(getActivity().getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
    getActivity().getSupportFragmentManager().executePendingTransactions();
    bottomSheetDialogFragment.getDialog().setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            onResume();
            MainActivity.updateMediaButtons();
        }
    });
Run Code Online (Sandbox Code Playgroud)

要关闭它,我从 Fragment 中调用 Dismiss() 。这样,它就会被关闭,但如果应用程序恢复,它会再次显示,这不是我的意图。

如果有人能帮助我解决这个问题,我会很高兴。我已经扫描了有关如何正确使用这些 BottomSheetDialogFragments 的各种教程,但我找不到我的错误。

顺便说一句,我在 onResume 中没有任何代码来测试它。

android bottom-sheet

3
推荐指数
1
解决办法
3025
查看次数

如何在BottomSheetDialog中的GridView中向上滚动?

我创建了一个里面BottomSheetDialog有一个GridView。当BottomSheetDialog被打开,你可以滚动下来正常。这样做会使BottomSheetDialog扩展到全屏并GridView正常向下滚动。

但是,当用户尝试向上滚动;而不是向上滚动GridViewBottomSheetDialog缩小并关闭。

我想要的是能够在GridViewBottomSheetDialog改变尺寸的情况下上下滚动。

怎么做?

我的代码:

final BottomSheetDialog dialog = new BottomSheetDialog(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.grid, null);
dialog.setContentView(view);
Run Code Online (Sandbox Code Playgroud)

网格.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <GridView
        android:background="#FFFFFF"
        android:id="@+id/gridview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="3"
        android:stretchMode="columnWidth"
        android:horizontalSpacing="4dp"
        android:verticalSpacing="4dp"
        android:gravity="center"
        />

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

android bottom-sheet

3
推荐指数
1
解决办法
1414
查看次数

我们如何设置折叠底板的最小高度

我可以成功添加峰值高度,但是在尝试设置底部工作表的最小高度时,我无法这样做,并且整个工作表都折叠了。所以我试图让它扩展到隐藏状态,但这对我来说还不够,因为它太高了。

我主要关心的是不要隐藏底片,如果隐藏或折叠它必须重新出现并设置最小高度

请提出一些建议:

下面是我的代码:

final View bottomSheet = findViewById(R.id.bottom_sheet2);
    mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
    mBottomSheetBehavior.setHideable(true);
    mBottomSheetBehavior.setPeekHeight(LinearLayout.LayoutParams.MATCH_PARENT);
    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

    mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(View bottomSheet, int newState) {
            if (newState == BottomSheetBehavior.STATE_EXPANDED) {

            }
            else if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            }
            else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {

            }
        }

        @Override
        public void onSlide(View bottomSheet, float slideOffset) {
        }
    });
Run Code Online (Sandbox Code Playgroud)

野兔是我的 xml:

        <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottom_sheet2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="45dp"
        android:clipToPadding="false"
        android:background="#00ffffff"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:elevation="6dp"
            app:cardCornerRadius="10dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_height="wrap_content">

            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:background="#fff" …
Run Code Online (Sandbox Code Playgroud)

android bottom-sheet

3
推荐指数
1
解决办法
3904
查看次数

如何将视图模型绑定到底板

我试图弄清楚如何将视图模型绑定到底部表,以便我可以使用视图模型上的可观察字段使底部表同时展开、折叠和隐藏。

谢谢!

android bottom-sheet android-viewmodel

3
推荐指数
1
解决办法
4030
查看次数

颤振设置状态不更新底部功能中的变量值

我有一个按钮,点击我调用下面的函数,它在下面创建一个底部。发生的事情是它根据列表数组值构建一个卡片列表。然后我想根据 onTap 手势更新其值的卡片之一。我注意到它检测到手势但没有更新它的值。最重要的是,我有一个全局变量定义为

String _localPNumberSelected="";
Run Code Online (Sandbox Code Playgroud)

在 onTap 我调用 setState

setState(() {                                                   
 _localPNumberSelected=vList[index]["pNumber"].toString();
});
Run Code Online (Sandbox Code Playgroud)

但这不会更新

children: [
  new Text('$_localPNumberSelected'),                                                
],
Run Code Online (Sandbox Code Playgroud)

这是完整的代码。

void _callQuickListModalBottomSheet(context){
    Future<void> future = showModalBottomSheet<void>(
      context: context,
      builder: (BuildContext bc){
          return Container(
            height: 280,
            margin: new EdgeInsets.fromLTRB(200, 0, 10, 0),
            child : new Container(
              decoration: new BoxDecoration(
                 color: Color.fromRGBO(36, 46, 66, 1),
                 borderRadius: new BorderRadius.only(
                   topLeft: const Radius.circular(20),
                   topRight: const Radius.circular(20)
                 ),                 
              ),
              child: new Column(                    
                      children: <Widget>[
                        new Container(
                        margin: new EdgeInsets.fromLTRB(10, 10, 10, 0),
                        height:45,
                        child: new …
Run Code Online (Sandbox Code Playgroud)

setstate flutter bottom-sheet

3
推荐指数
2
解决办法
5686
查看次数

使用 RecyclerView 时未显示 BottomSheet

我有底部工作表的以下代码

xml文件

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/titleTextview"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:fontFamily="sans-serif"
        android:text="@string/choose_option"
        android:textColor="@android:color/darker_gray"
        android:textSize="14sp"
        android:textStyle="normal"
        app:layout_constraintBottom_toTopOf="@id/recyclerView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/titleTextview" />

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

看法

class AttributeOptionsBottomSheet(val viewModel: AttributeOptionsViewModel) : BottomSheetDialogFragment() {

    override fun getTheme(): Int = R.style.AppBottomSheetDialogTheme

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? = inflater.inflate(R.layout.bottom_sheet_attributes, container, false)
        .also { view ->
            view.findViewById<RecyclerView>(R.id.recyclerView).apply {
                context?.let {
                    layoutManager = LinearLayoutManager(Activity())
                    adapter = AttributeOptionsAdapter(viewModel)
                    viewModel.dismissView.observe({ lifecycle }) …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-recyclerview bottom-sheet

3
推荐指数
1
解决办法
1332
查看次数

调整颤动中的底片

我的应用程序中有一个底部工作表,对于 5 + 尺寸的手机可以正确显示,但是当我在较小屏幕的手机上运行时,我会得到如下所示的结果

在此输入图像描述

问题在于填充跨越了范围,是否有其他方法来创建底片,并且其内容大小应该特定于设备?如何自动调整字体大小,以及根据设备特定的填充。

下面是相同的代码

showModalBottomSheet<void>(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(10.0),
        ),
        context: context,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return FractionallySizedBox(
              heightFactor: 0.2,
              child: Padding(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 22.0,
                    vertical: 14.0,
                  ),
                  child: Column(
                    children: <Widget>[
                      ListTile(
                          leading: Icon(Icons.remove_red_eye),
                          title: Text(
                            "View",
                            overflow: TextOverflow.ellipsis,
                            textAlign: TextAlign.justify,
                            maxLines: 1,
                            style: TextStyle(
                              fontSize:
                                  ScreenUtil(allowFontScaling: true).setSp(50),
                            ),
                          ),
                          onTap: () {
                            Navigator.of(context).pop();
                            setGenerateReportView(context, count, data);
                          }),
                      ListTile(
                          leading: Icon(Icons.file_download),
                          title: Text(
                            "Download",
                            overflow: TextOverflow.ellipsis,
                            textAlign: TextAlign.justify,
                            maxLines: 1,
                            style: TextStyle(
                              fontSize: …
Run Code Online (Sandbox Code Playgroud)

flutter bottom-sheet

3
推荐指数
2
解决办法
5649
查看次数

带有 RecyclerView 和其他视图的 BottomSheet

我有一个带有BottomSheet的CoordinatorLayout。如果Bottomsheet 只有一个RecyclerView,则一切正常。我试图在 RecyclerView 顶部添加一些 Textview 和按钮,但是当它到达顶部高度时,recyclerview 会在另一个视图下方滚动。我希望其他视图也滚动。如果BottomSheet 只包含其他视图(没有Recyclerview)也可以正常工作。当我结合 RecyclerView 和其他视图元素(按钮、TextView)时,滚动不符合预期。

我想将 Recyclerview 上方的视图设置为列表的第一项,但这增加了适配器的复杂性。

   <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      app:behavior_hideable="false"
      app:behavior_peekHeight="80dp"
      app:layout_behavior="@string/bottom_sheet_behavior">

      <Button
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Button 1"/>
      <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Text 2"/>
      <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Text 3"/>

      <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:background="@android:color/white"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:clipToPadding="true"/>
   </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-coordinatorlayout bottom-sheet

3
推荐指数
1
解决办法
5611
查看次数

MotionLayout 中具有 BottomSheetBehaviour 的 RecyclerView 在触摸 RecyclerView 时不会滚动

MotionLayout 中的 RecyclerView 具有 BottomSheetBehaviour,当用户在触摸 recyclerview 时拖动 BottomSheet 时,它不会向上拖动。

当与 ConstraintLayout 一起使用或当用户触摸 recyclerview 以外的任何地方时,它可以完美地工作。

正如你所看到的,我在 CoordinatorLayout 中使用了 MotionLayout,而 RecyclerView 在 MotionLayout 中。

只需将其替换为 ConstraintLayout 一切就完美了。因为我正在使用 MotionLayout,所以不确定如何处理 MotionLayout 内的 recyclerview。

代码:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/rounded_bottom_sheet"
        android:clickable="true"
        android:focusable="true"
        app:layoutDescription="@xml/bottom_sheet_scene"
        app:behavior_hideable="false"
        app:behavior_peekHeight="190dp"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <View
            android:id="@+id/handle"
            android:layout_width="24dp"
            android:layout_height="4dp"
            android:background="@drawable/handle_background" />

        <EditText
            android:id="@+id/drop_search_et"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_8sdp"
            android:layout_marginTop="@dimen/_24sdp"
            android:layout_marginEnd="@dimen/_12sdp"
            android:background="@drawable/rounded_grey_edit_text"
            android:maxLines="1"
            android:inputType="text"
            android:ellipsize="end"
            android:hint="Where do you want to go?"
            android:paddingStart="@dimen/_10sdp"
            android:paddingTop="@dimen/_6sdp"
            android:paddingEnd="@dimen/_10sdp"
            android:paddingBottom="@dimen/_6sdp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/drop_image"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/search_recycler_view"
            android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-recyclerview bottom-sheet android-motionlayout

3
推荐指数
1
解决办法
1857
查看次数

Android Studio 参数化类的原始使用

我的 Android 项目中有此代码:

final BottomSheetBehavior infoBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.info_view));
        infoBottomSheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_DRAGGING) {
                    infoBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                }
            }
            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
            }
        });
Run Code Online (Sandbox Code Playgroud)

下一个警告出现在 BottomSheetBehavior 上: Raw use of parameterized class 'BottomSheetBehavior'

有人知道如何避免此警告吗?

android parameterized-class bottom-sheet

3
推荐指数
1
解决办法
1138
查看次数