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

作者:只要你能好 时间:2021-08-08 08:07:42 

本文实例讲述了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,popupWindow,弹出窗体
0
投稿

猜你喜欢

  • 详解C# ConcurrentBag的实现原理

    2022-11-17 02:26:05
  • 在Framework 4.0中:找出新增的方法与新增的类(一)

    2021-07-07 05:26:07
  • Android屏蔽软键盘并且显示光标的实例详解

    2023-01-16 16:54:20
  • 关于Mybatis-Plus Update更新策略问题

    2022-04-14 19:29:24
  • Spring Boot中使用JDBC Templet的方法教程

    2021-09-06 06:04:38
  • Android提高之MediaPlayer播放网络视频的实现方法

    2021-07-03 06:25:29
  • Java中定时器Timer致命缺点案例详解

    2022-08-27 08:38:45
  • Java二维数组实战案例

    2022-08-13 08:59:25
  • AndroidStudio4.0 New Class的坑(小结)

    2022-07-29 15:06:48
  • Map集合之HashMap的使用及说明

    2022-07-23 15:56:56
  • 浅谈Spring中Bean的作用域、生命周期

    2023-11-14 02:44:21
  • 详解Java注解知识点

    2021-06-24 18:39:12
  • Javaweb实现在线人数统计代码实例

    2023-01-17 10:19:24
  • Spring中BeanFactory与FactoryBean接口的区别详解

    2022-06-17 11:22:22
  • java的Arrays工具类实战

    2023-08-21 15:46:36
  • springmvc不进入Controller导致404的问题

    2023-03-18 01:29:20
  • 使用spring通过aop获取方法参数和参数值

    2022-06-04 16:28:33
  • SpringBoot配置Email发送功能实例

    2022-03-07 20:52:20
  • Spring一步到位精通拦截器

    2022-01-03 18:31:50
  • MyBatis的逆向工程详解

    2022-12-03 11:06:10
  • asp之家 软件编程 m.aspxhome.com