Android实现底部半透明弹出框PopUpWindow效果
程序员文章站
2022-03-24 18:16:51
android底部半透明弹出框popupwindow,供大家参考,具体内容如下
layout布局:
android底部半透明弹出框popupwindow,供大家参考,具体内容如下
layout布局:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#66fafafa" android:orientation="vertical"> <linearlayout android:layout_width="match_parent" android:layout_height="122dp" android:id="@+id/ll_popupwindow" android:background="#ffffff" android:layout_alignparentbottom="true" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="26dp" android:orientation="horizontal"> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/popwindow_facebook" android:drawabletop="@mipmap/gif_more_facebook" android:drawablepadding="12dp" android:gravity="center" android:text="facebook" android:textcolor="#4d4d4d" android:textsize="12sp" /> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/popwindow_whatsapp" android:drawabletop="@mipmap/gif_more_whatsapp" android:drawablepadding="12dp" android:gravity="center" android:text="whatsapp" android:visibility="gone" android:textcolor="#4d4d4d" android:textsize="12sp" /> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/popwindow_report" android:drawabletop="@mipmap/gif_more_report" android:drawablepadding="12dp" android:gravity="center" android:text="report" android:textcolor="#4d4d4d" android:textsize="12sp" /> </linearlayout> </linearlayout> </relativelayout>
布局示意:
代码部分:
/* * 在当前页面调用initpopupwindow方法,底部弹出popupwindow * 重点在popupwindow的layout最外层布局设置android:background="#66fafafa" 半透明 * */ private void initpopupwindow(view root, final string uuid, final string title){ log.d("click","init popopop"); //inflate得到布局 ,底部弹出框的view final view popview = layoutinflater.from(mcontext).inflate( r.layout.layout_bottom_popwindow, null); view rootview = root; // 当前页面的根布局 //创建popupwindow对象 宽高占满页面 final popupwindow popupwindow = new popupwindow(popview, windowmanager.layoutparams.match_parent, windowmanager.layoutparams.match_parent); popupwindow.settouchable(true); // 设置弹出动画 popupwindow.setanimationstyle(r.style.anim_edit_text_popup); // 显示在根布局的底部 popupwindow.showatlocation(rootview, gravity.bottom | gravity.left, 0, 0); //点击底部弹出框之外的部分让popupwindow 消失 popview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { int height = popview.findviewbyid(r.id.ll_popupwindow).gettop(); int y=(int) event.gety(); if(event.getaction()==motionevent.action_up){ if(y<height){ popupwindow.dismiss(); } } return true; } }); //弹出框中控件的点击事件 textview share_facebook= (textview) popview.findviewbyid(r.id.popwindow_facebook); share_facebook.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { share_facebook(uuid,title); popupwindow.dismiss(); } }); final textview share_whatsapp= (textview) popview.findviewbyid(r.id.popwindow_whatsapp); boolean whatsappfound = checkutils.isappinstalled(mcontext, "com.whatsapp"); if (whatsappfound) { share_whatsapp.setvisibility(view.visible); share_whatsapp.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { share_whatsapp(uuid,title); } }); } textview report= (textview) popview.findviewbyid(r.id.popwindow_report); report.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent intent = new intent(mcontext, reportactivity.class); intent.putextra("fromch", true); intent.putextra("tid", uuid); mcontext.startactivity(intent); popupwindow.dismiss();<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="100" android:fromydelta="0.0" android:toydelta="100%" /> </set> } }); }
动画部分
进入时从最下方弹出到最上方
消失时从最上方向下移动直到隐藏
<style name="anim_edit_text_popup"> <item name="android:windowenteranimation">@anim/popup_in</item> <item name="android:windowexitanimation">@anim/popup_out</item> </style>
popup_in:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="100" android:fromydelta="100.0%" android:toydelta="0.0" /> </set>
pop_out:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="100" android:fromydelta="0.0" android:toydelta="100%" /> </set>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读
-
Android 实现抖音头像底部弹框效果的实例代码
-
Android 之BottomsheetDialogFragment仿抖音评论底部弹出对话框效果(实例代码)
-
Android 之BottomsheetDialogFragment仿抖音评论底部弹出对话框效果(实例代码)
-
Android实现底部对话框BottomDialog弹出实例代码
-
Android 开发使用PopupWindow实现弹出警告框的复用类示例
-
Android仿Iphone屏幕底部弹出半透明PopupWindow效果
-
android超级难题Dialog输入法底部弹出无论设置何种模式实现点击编辑框输入框自动顶起问题解决...
-
Android实现底部半透明弹出框PopUpWindow效果
-
Android实现底部弹出PopupWindow背景逐渐变暗效果
-
简单实现弹出弹框页面背景半透明灰,弹框内容可滚动原页面内容不可滚动的效果(JQuery)