全屏底部弹出式片段界面

3

我一直在尝试在Android中实现底部表单片段,但一直无法将其默认缩放到全屏。我甚至尝试将其状态设置为STATE_EXPANDED。

public void setupDialog(Dialog dialog, int style) {
       super.setupDialog(dialog, style);
       View v = View.inflate(getContext(), R.layout.fragment_my_bottom_sheet_dialog, null);
       dialog.setContentView(v);

       CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) v.getParent()).getLayoutParams();
       CoordinatorLayout.Behavior behavior = params.getBehavior();

       if (behavior != null && behavior instanceof BottomSheetBehavior) {
           Log.d(TAG, "Inside if");
           ((BottomSheetBehavior) behavior).setState(BottomSheetBehavior.STATE_EXPANDED);
           ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetCallback);
       }
   }

但这会破坏从底部浮动的表单的动画效果。我正在尝试创建一个带有全屏和工具栏的模态底部表格,其中包含一个关闭(X)按钮,如下所示:全屏底部表格。如果有人能帮忙解决这个问题,我将不胜感激。

但这会破坏从底部浮动的表格的动画效果。 您的意思是当片段被附加时,底部表格从底部向上运动? - muthuraj
我不确定你是否还在寻找答案,但是这个人的解决方案有效。 - Caleb Lewis
1个回答

2
我能理解的是您想要一个滑动面板来执行设置。我强烈建议您使用umano的Android Sliding Up Panel库。 它有两个子元素,一个用于活动/片段,另一个用于面板。
<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoPanelHeight="68dp"
    sothree:umanoShadowHeight="4dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="Main Content"
        android:textSize="16sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center|top"
        android:text="The Awesome Sliding Up Panel"
        android:textSize="16sp" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

我只是在尝试这个,问题是我想使用单独的activity/fragment来实现它,因为我将有一些本地变量和计算,我希望将其隔离到面板中。 - Parichit
没有问题。在您的面板布局中,只需添加一个FrameLayout。现在创建一个片段、片段布局并使用FragmentManager将其填充到来自您活动的FrameLayout中。这样您的面板逻辑将在单独的类中。 - Prince Bansal
如果你遇到任何困难,我会更新代码。但是如果你理解我的意思,那么这就可以了。 :) - Prince Bansal
我尝试过了,但是遇到了另一个问题。我想在片段中添加一个单独的工具栏,其中包含菜单项和关闭按钮,并避免重置活动工具栏。你知道我可以怎么做吗? - Parichit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接