Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Show layout from the bottom of the screen on button click

Tags:

android

Recently i have installed an application from the play store named walnut where i saw a new feature for popup.In the home screen there is a FloatingActionMenu,when clicking on the menu button it will expand with the items on it,on top of that expanded menu there is an option for add account, and on clicking that option a popup will come from the bottom of the screen to a certain height.I likes to know what feature is used for that popup from the bottom of the screen.Is it really a popup or sliding drawer? I want to use exactly the same feature in my android application.If anyone knows about this feature please help me.Below is the screenshot of this popup layout that comes on button click in walnut application. Popup layout from the bootom of the screen

like image 412
KJEjava48 Avatar asked Mar 23 '16 09:03

KJEjava48


People also ask

How do you place a button at the bottom of the screen in android?

If you want to add Buttons to the bottom of your android layout XML file you can achieve it using attribute layout_gravity on LinearLayout or TableRow layout. Below your Parent Layout tag add a LinearLayout or TableRow with attribute android:layout_gravity="bottom".

How do I fix the bottom layout on my android?

You can set the layout_height="0dp" of your header, footer and ScrollView and define a layout_weight . Just play around with the values until you find out which works best. The resulting heights of header and footer would dynamically change with the screensize.

What is a relative layout?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).


1 Answers

you can use dialog with custom layout in it. only thing you have to do is call it from bottom and use style as material dialog sheet like this

 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();

I change my layout height to 800 instead of wrap content and here is the result.

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>

anim

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

like image 95
KDeogharkar Avatar answered Oct 18 '22 17:10

KDeogharkar