AndroID底部半透明d出框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方法,底部d出popUpWindow * 重点在popUpWindow的layout最外层布局设置androID:background="#66fafafa" 半透明 * */ private voID initPopUpWindow(VIEw root,final String uuID,final String Title){ Log.d("click","init popopop"); //inflate得到布局 ,底部d出框的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); // 设置d出动画 popupWindow.setAnimationStyle(R.style.anim_edit_text_popup); // 显示在根布局的底部 popupWindow.showAtLocation(rootVIEw,Gravity.BottOM | Gravity.left,0); //点击底部d出框之外的部分让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; } }); //d出框中控件的点击事件 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> } }); }
动画部分
进入时从最下方d出到最上方
消失时从最上方向下移动直到隐藏
<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实现底部半透明d出框PopUpWindow效果全部内容,希望文章能够帮你解决Android实现底部半透明d出框PopUpWindow效果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)