本文实例为大家分享了Android仿苹果手机屏幕底部弹出效果的具体代码,供大家参考,具体内容如下
主要。xml如下:
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android " android: layout_width="宽和" android: layout_height="宽和" 比; & lt;按钮 android: id=癅 + id/按钮” android:文本=" popupWindow " android: layout_width="宽和" android: layout_height=" wrap_content "/比; & lt;/RelativeLayout>>之前风格。xml如下:
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; resources> & lt;样式名=" popupAnimation "父=癮ndroid:动画”比; & lt;项目名称=" android: windowEnterAnimation "祝辞@anim/in & lt;项目名称=" android: windowExitAnimation "祝辞@anim/out & lt;/style> & lt;/resources> popupwindow.xml如下: & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android " android: layout_width=" match_parent " android: layout_height=" match_parent " android:背景=" # b5555555”比; LinearLayout & lt; android: layout_width=" match_parent " android: layout_height=" wrap_content " android: layout_alignParentBottom=" true " android: layout_marginBottom=" 12底" android: paddingLeft=" 10底” android: paddingRight=" 10底” 面向android:=按怪薄北? & lt;按钮 android: id=癅 + id/confirmButton” android: layout_width="宽和" android: layout_height=" wrap_content " android: layout_gravity="中心" android:文本="确定”/比; & lt;按钮 android: id=癅 + id/cancleButton” android: layout_marginTop=" 12底" android: layout_width="宽和" android: layout_height=" wrap_content " android: layout_gravity="中心" android:文本="取消”/比; & lt;/LinearLayout> & lt;/RelativeLayout> >之前。xml如下:
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;设置xmlns: android=" http://schemas.android.com/apk/res/android "比; & lt;翻译 android: fromYDelta=" 5000 " android: toYDelta=" 0 " android:持续时间=" 1500 "/比; & lt;/set> >之前。xml如下:
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;设置xmlns: android=" http://schemas.android.com/apk/res/android "比; & lt;翻译 android: fromYDelta=" 0 " android: toYDelta=" 5000 " android:持续时间=" 1500 "/比; & lt;/set> >之前PopupWindowTestActivity。Java如下:
进口android.app.Activity; 进口android.graphics.drawable.BitmapDrawable; 进口android.os.Bundle; 进口android.view.Gravity; 进口android.view.LayoutInflater; 进口android.view.View; 进口android.view.View.OnClickListener; 进口android.view.ViewGroup.LayoutParams; 进口android.widget.Button; 进口android.widget.PopupWindow;/* * *演示描述: *仿Iphone从屏幕底部弹出半透明的PopupWindow */公开课PopupWindowTestActivity延伸活动{ 私人按钮按钮; 私人按钮confirmButton; 私人按钮cancleButton; 私人PopupWindow PopupWindow; 私人观点popupWindowView; @Override 公共空间onCreate(包savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.main); init (); } 私人空间init () { 按钮=(按钮)findViewById (R.id.button); 按钮。setOnClickListener(新ButtonOnClickListener ()); } 私人类ButtonOnClickListener实现OnClickListener { @Override 公共空间onClick(查看v) { 开关(v.getId ()) { 案例R.id.button: LayoutInflater增压泵=(LayoutInflater) getSystemService (LAYOUT_INFLATER_SERVICE); popupWindowView=inflater.inflate(出来。popupwindow, null); popupWindow=new popupWindow (popupWindowView LayoutParams。宽和LayoutParams.FILL_PARENT,真正的); popupWindow。setBackgroundDrawable(新BitmapDrawable ());//设置PopupWindow的弹出和消失效果 popupWindow.setAnimationStyle (R.style.popupAnimation); confirmButton=(按钮)popupWindowView.findViewById (R.id.confirmButton); confirmButton。setOnClickListener(新ButtonOnClickListener ()); cancleButton=(按钮)popupWindowView.findViewById (R.id.cancleButton); cancleButton。setOnClickListener(新ButtonOnClickListener ()); popupWindow。showAtLocation (confirmButton重力。中心,0,0); 打破; 案例R.id.confirmButton: System.out.println(“点击了确定按钮”); 打破; 案例R.id.cancleButton: popupWindow.dismiss (); 打破; 默认值: 打破; } }} }Android仿苹果手机屏幕底部弹出半透明PopupWindow效果