发布于 2017-09-26 02:33:35 | 139 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android popupWindow弹出窗体实现方法,结合具体实例形式分析了Android弹出窗体的布局及popupwindow属性设置、事件监听相关操作技巧,需要的朋友可以参考下

本文实例讲述了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程序设计有所帮助。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务