安卓 : Show layout from the bottom of the screen on button click

标签 android

最近我从名为 walnut 的 Play 商店安装了一个应用程序,在那里我看到了弹出的新功能。在主屏幕上有一个 FloatingActionMenu,当单击菜单按钮时,它会展开并显示其上的项目,在顶部该扩展菜单中有一个用于添加帐户的选项,单击该选项时,弹出窗口将从屏幕底部到达一定高度。我想知道屏幕底部的弹出窗口使用什么功能。它真的是弹出式或滑动式抽屉吗?我想在我的 android 应用程序中使用完全相同的功能。如果有人知道此功能,请帮助我。下面是在核桃应用程序中单击按钮时弹出布局的屏幕截图。 Popup layout from the bootom of the screen

最佳答案

您可以使用带有自定义布局的对话框。您唯一需要做的就是从底部调用它并像这样使用样式作为 Material 对话框表

 final Dialog mBottomSheetDialog = new Dialog(getActivity(), R.style.MaterialDialogSheet);
                            mBottomSheetDialog.setContentView(view); // your custom view.
                            mBottomSheetDialog.setCancelable(true);
                            mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                            mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM);
                            mBottomSheetDialog.show();

我将布局高度更改为 800 而不是包装内容,结果如下。

style.xml

<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
    </style>



<style name="MaterialDialogSheetAnimation">
        <item name="android:windowEnterAnimation">@anim/popup_show</item>
        <item name="android:windowExitAnimation">@anim/popup_hide</item>
    </style>

动物

popup_show.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="100%p"
        android:toYDelta="0"
        android:duration="300"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
</set>

popup_hide.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="0"
        android:toYDelta="100%p"
        android:duration="300"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
</set>

enter image description here

关于安卓 : Show layout from the bottom of the screen on button click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36174251/

相关文章:

Android 浏览器媒体播放器(stagefright?)显示的媒体名称

android - 通过 HTTP 访问 Web 服务时未获得所需的输出

android - 检查Android应用程序是否未安装,然后提示Toast消息

Android NDK 中通过 SWIG 的 Java 字符串用奇怪的字符代替空字节

java - 无法实例化应用程序 java.lang.ClassNotFoundException

java - 具有切换功能的小部件

android - 如何使我的布局水平和垂直滚动?

android - Inbrowser android api的

android - 如何在 Android 中使用 WCF .SVC

android - 我如何在 mysql 表(lat 和 long 存储的位置)中查询最接近输入位置(lat 和 long)的位置?