当前位置: 移动技术网 > IT编程>移动开发>Android > Android popupWindow弹出窗体实现方法分析

Android popupWindow弹出窗体实现方法分析

2019年07月24日  | 移动技术网IT编程  | 我要评论

北京地铁15号线路图,熔火激流的主宰,明星红毯出丑

本文实例讲述了android popupwindow弹出窗体实现方法。分享给大家供大家参考,具体如下:

1. 建立popupwindow显示的布局页面(普通的view任意布局)

<?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="80dip"
  android:background="@drawable/popup_yellow_window_bg"
  android:orientation="horizontal" >
  <textview
      android:id="@+id/popupwindow_app_uninstall_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
      android:layout_marginbottom="5dip"
      android:layout_margintop="5dip"
      android:drawabletop="@drawable/kn_malware_scan_deep_click"
      android:text="卸 载"/>
</linearlayout>

2. activity中布局加载以及填充,建立popupwindow对象,设置相应参数或属性

view contentview = view.inflate(getapplicationcontext(), r.layout.popup_window, null);
linearlayout ll_uninstall = (linearlayout) contentview.findviewbyid(r.id.ll_uninstall);
//设置popupwindow内布局组件的监听(与其他组件相似)
myonclicklistener l = new myonclicklistener(position);
ll_uninstall.setonclicklistener(l);
popupwindow mpopupwindow = new popupwindow(contentview, viewgroup.layoutparams.wrap_content, 70);
int[] arrayofint = new int[2];
view.getlocationinwindow(arrayofint);
int x = arrayofint[0] + 60;
int y = arrayofint[1];
//1 指定popupwindow的背景  2 popupwindow能够获得焦点
mpopupwindow.setbackgrounddrawable(new bitmapdrawable());
mpopupwindow.setfocusable(true);
mpopupwindow.showatlocation(view, gravity.left|gravity.top, x, y);
//在合适位置取消popupwindow显示
mpopupwindow.dismiss();

更多关于android相关内容感兴趣的读者可查看本站专题:《android窗口相关操作技巧总结》、《android开发入门与进阶教程》、《android调试技巧与常见问题解决方法汇总》、《android基本组件用法总结》、《android视图view技巧总结》、《android布局layout技巧总结》及《android控件用法总结

希望本文所述对大家android程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网