The bottom pop-up box is often needed in the project, and here I'll tidy up one of the more convenient ways I use it (the bottom is a dialog with a horizontal full screen).
The effect diagram looks like this (only the key parts are shown):
The steps are as follows:
1. Define a dialog layout (lay_share.xml)
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:background=" @color White "android:orientation=" vertical "> <linearlayout android:layout_width=" match_parent "Android:layout_ height= "Wrap_content" android:gravity= "center_vertical" android:orientation= "horizontal" android:paddingBottom= "@ Dimen/padding_15 "android:paddingtop=" @dimen/padding_15 "> <view android:layout_width=" 0DP "Android:layout_ height= "0DP" android:layout_weight= "1"/> <textview android:layout_width= "Wrap_content" android:layout_height = "Wrap_content" android:drawablepadding= "@dimen/padding_5" android:drawabletop= "@mipmap/ic_weixin_share" Android:
gravity= "center" android:text= "micro-letter" android:textcolor= "@color/color_999999" android:textsize= "@dimen/text_14"/> <view android:layout_width= "0DP" android:layout_height= "0DP" android:layout_weight= "1"/> <TextView android:layout_width= "wrap_content" android:layout_height= wrap_content "android:drawablepadding=" @dimen /padding_5 "android:drawabletop=" @mipmap/ic_circle_share "android:gravity=" center "android:text=" Circle of Friends "Android: Textcolor= "@color/color_999999" android:textsize= "@dimen/text_14"/> <view android:layout_width= "0DP" Android : layout_height= "0DP" android:layout_weight= "1"/> <textview android:layout_width= "Wrap_content" Android: layout_height= "Wrap_content" android:drawablepadding= "@dimen/padding_5" android:drawabletop= "@mipmap/ic_weibo_ Share "android:gravity=" center "android:text=" Weibo "android:textcolor=" @color/color_999999 "android:textsize=" @dimen /text_14 "/> <view android:layout_width=" 0DP "android:layout_height=" 0DP "android:layout_weight=" 1 "/> </ linearlayout> <view android:layout_width= "match_parent" android:layout_height= "0.5DP" Android:layout_ marginleft= "@dimen/padding_10" android:layout_marginright= "@dimen/padding_10" android:background= "@color/color_c9c9c9 "/> <textview android:id= @+id/tv_cancel" android:layout_width= "Match_parent" Android:layout_ height= "wrap_content" android:gravity= "center" android:padding= "@dimen/padding_15" android:text= "Cancel" Android: Textcolor= "@color/color_666666" android:textsize= "@dimen/text_18"/> </LinearLayout>
2. Define pop-up pop-up animation (Dialog_enter.xml)
<?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<translate
android:duration="
android:fromydelta= "100%p"
android:toydelta= "0"/>
</set>
dialog_enter.xml
3. Define Popup Hidden Animation (dialog_exit.xml)
<?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<translate
android:duration="
android:fromydelta= "0"
android:toydelta= "100%p"/>
</set>
dialog_exit.xml
4. Define animation style
<!--pop-up animation-->
<style name= "share_animation" parent= "android:animation" >
<item name= "Android : Windowenteranimation "> @anim/dialog_enter</item>
<item name=" Android:windowexitanimation ">@ Anim/dialog_exit</item>
</style>
5. Define dialog box style
<!--dialog box style-->
<style name= "Dialog_bottom_full" parent= "Android:style/theme.dialog" >
<item Name= "Android:windowbackground" > @android:color/transparent</item>
<item name= "Android: Windownotitle ">true</item>
<item name=" android:windowisfloating ">true</item>
<item name= "Android:windowcontentoverlay" > @null </item>
<item name= "Android: Scrollhorizontally ">true</item>
</style>
6. Finally, call the ShowDialog () method directly at the place where you need to eject dialog from the bottom
/** * Display share pop-up/private void ShowDialog () {if (Msharedialog = null) {Initsharedialog
();
} msharedialog.show (); /** * Initialize sharing pop-up/private void Initsharedialog () {msharedialog = new Dialog (this, r.style.dialog_bottom_full); Msharedi
Alog.setcanceledontouchoutside (TRUE);
Msharedialog.setcancelable (TRUE);
window window = Msharedialog.getwindow ();
Window.setgravity (Gravity.bottom);
Window.setwindowanimations (r.style.share_animation);
View view = View.inflate (this, r.layout.lay_share, null); View.findviewbyid (R.id.tv_cancel). Setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View
View) {if (Msharedialog!= null && msharedialog.isshowing ()) {Msharedialog.dismiss ();}}});
Window.setcontentview (view); Window.setlayout (WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//Set Horizontal Full-screen}
The above is a small series to introduce the Android from the bottom of the pop-up dialog (horizontal Mansi) of the example code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!