Popupwindow 的简单实用,(显示在控件下方)
第一步:
private PopupWindow mPopupWindow; 第二步:写一个popupwindow的布局文件XML
<?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="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#669E9E9E">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#E4E4E4"
>
<TextView
android:id="@+id/popupwindow_Jan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="一月份"
android:gravity="center"
/>
<TextView
android:id="@+id/popupwindow_Feb"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="二月份"
android:gravity="center"
/>
<TextView
android:id="@+id/popupwindow_Mar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="三月份"
android:gravity="center"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
第三步:在Activity写代码
public void onClick(View v) {
switch (v.getId()) {
case R.id.home_travel_modes_yuefen_textview:
showPopupWindow(v);
break;
case R.id.popupwindow_Jan:
showToastMsg("一月份");
break;
case R.id.popupwindow_Feb:
showToastMsg("二月份");
break;
default:
break;
}
public void showPopupWindow(View v){
View contentView = LayoutInflater.from(HomeTravelModesActivity.this).inflate(R.layout.home_popuplayout, null);
TextView JanText = (TextView)contentView.findViewById(R.id.popupwindow_Jan);
TextView FebText = (TextView)contentView.findViewById(R.id.popupwindow_Feb);
TextView MarText = (TextView)contentView.findViewById(R.id.popupwindow_Mar);
JanText.setOnClickListener(this);
FebText.setOnClickListener(this);
MarText.setOnClickListener(this);
final PopupWindow popupWindow = new PopupWindow(contentView,
LinearLayout.LayoutParams.MATCH_PARENT, 300, true);
popupWindow.setTouchable(true);
// popupWindow.setTouchInterceptor(new View.OnTouchListener() {
//
// @Override
// public boolean onTouch(View v, MotionEvent event) {
//
// Log.i("mengdd", "onTouch : ");
//
// return false;
// // 这里如果返回true的话,touch事件将被拦截
// // 拦截后 PopupWindow的onTouchEvent不被调用,这样点击外部区域无法dismiss
// }
// });
// 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
// 我觉得这里是API的一个bug
popupWindow.setBackgroundDrawable(getResources().getDrawable(
R.mipmap.ic_launcher));
// 设置好参数之后再show
popupWindow.showAsDropDown(v);
}
注:
若在Activity的onCreate()方法中直接写弹出PopupWindow()方法报错,因为Activity没有完全启动是不能弹出PopupWindow的,那我们只需要在Activity完全启动后在弹出PopupWindow就行了。
重写一下onWindowFocusChanged()方法:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//弹出PopupWindow的具体代码
}
Popupwindow 的简单实用,(显示在控件下方)的更多相关文章
- Android自定义PopupWindow显示在控件上方或者下方
记录学习之用 View view = mInflater.inflate(R.layout.layout_popupwindow, null); PopUpwindowLayout popUpwind ...
- ASP.NET AjaxControlToolkit-Framework4.0 配置实用(简单介绍CalendarExtender日期控件)
1:下载:AjaxControlToolkit Ajax Control Toolkit .NET 4 Ajax Control Toolkit .NET 4.5 Ajax Control Toolk ...
- Winform开发框架之肖像显示保存控件的实现
我们在开发一些Winform程序的时候,除了常规的显示普通数据外,有的时候需要显示一些人员肖像或者一些车辆等物体的图片,一般这些内容较小,所以以二进制存储在数据库是一个不错的方案.但由于它们虽然很常用 ...
- WPF教程十一:简单了解并使用控件模板
WPF教程十一:简单了解并使用控件模板 这一章梳理控件模板,每个WPF控件都设计成无外观的,但是行为设计上是不允许改变的,比如使用Button的控件时,按钮提供了能被点击的内容,那么自由的改变控件外观 ...
- [转]一种简单的js时间控件
使用方法: 粘贴代码到文本文档中,文档名称为datetime.js,然后在html文件中引用如下代码即可 <input name="shijian1" id="sh ...
- (转)sl简单自定义win窗体控件
sl简单自定义win窗体控件 相信大家接触过不少win窗体控件ChildWin子窗口就的sl自带的一个 而且网上也有很多类似的控件,而今天我和大家分享下自己制作个win窗体控件,希望对初学 ...
- 【转】silverlight telerik RadGridView 列头显示其他控件
<telerik:GridViewDataColumn DataMemberBinding="{Binding target_id}" IsFilterable=" ...
- AngularJS进阶(七)实现根据不同条件显示不同控件
AngularJS实现根据不同条件显示不同控件 由于项目需求,需要实现根据不同条件显示不同控件的功能.具体要求如下图所示: 即当选择"每单固定减"时,下方只显示"减免金额 ...
- BitmapImage处理网络图片,例如阿里云获取的图片。异步加载到需要显示的控件上。提升速度非常明显。
想直接把网络图片赋给控件,又要下载又要缓存,速度非常慢.不流畅. 需要进行处理,异步加载会显著提升速度.方法如下: public static BitmapImage ByteArrayToBitma ...
随机推荐
- JSP页面格式化货币金额,千分位
<fmt:formatNumber value="${值}" pattern="currency"></fmt:formatNumber> ...
- [转载]Linux命令笔记
*以下内容均来自于网络转载,感谢原作者分享 <对Linux新手非常有用的20个命令> 传送门 英文原文为“Switching From Windows to Nix or a Newbie ...
- 第一次点击Div1显示Div2,再次点击Div1的时候又隐藏Div2
要使用Jquery来实现,记得引用Jquery库哦,代码如下: $(document).ready(function(){ $("#ck1").click(function(){ ...
- Mysql之INFORMATION_SCHEMA解析1
INFORMATION_SCHEMA库是Mysql提供的一个系统库,保存了数据库的原数据,方便用户监控与管理Msyql. 现在单说与INNODB相关的库:INNODB_SYS_TABLES,INNOD ...
- nginx 配一个简单的静态文件服务器 和一个虚似机
下面是个图片服务器: server { listen ; server_name img.xxx.xxx.com; root /data/site/img.xxx.xxx.com; access_lo ...
- python 取两数的百分比
Python (r266:, Jan , ::) [GCC (Red Hat -)] on linux2 Type "help", "copyright", & ...
- SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
http://blog.csdn.net/isea533/article/details/33397735
- C#的初始化器
using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...
- ASP.NET Web Api 使用CacheCow和ETag缓存资源(转载)
转载地址:http://www.cnblogs.com/fzrain/p/3618887.html 前言 本文将使用一个开源框架CacheCow来实现针对Http请求资源缓存,本文主要介绍服务器端的缓 ...
- 拷贝,集合,函数,enumerate,内置函数
1.拷贝 字符串和数字.赋值 id一样 import copy #提供拷贝功能 copy.copy() #原来的和现在的一起修改,不用修改时用浅copy,节省内存,复制最外层 copy.deepcop ...