PopupWindow弹窗详解以及相关方法说明
来源:互联网 发布:vlad算法 编辑:程序博客网 时间:2024/05/16 15:11
layout_detail_traffic_item.xml文件中:其中text随便填就好,我这里是引用string.xml文件中的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="500dp"
android:layout_height="200dp"
android:background="#EDEDED"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5">
</TextView>
<TextView
android:id="@+id/detail_traffic_day"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/detail_traffic_text_day"
android:textColor="#404040"
android:textSize="14dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5">
</TextView>
<TextView
android:id="@+id/detail_traffic_week"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/detail_traffic_text_week"
android:textColor="#404040"
android:textSize="14dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5">
</TextView>
<TextView
android:id="@+id/detail_traffic_month"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/detail_traffic_text_month"
android:textColor="#404040"
android:textSize="14dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5">
</TextView>
</LinearLayout>
在你想要点击的某个控件后弹出这个窗口,则在这个控件的onclick方法中的相应位置添加以下代码:
JAVA代码:
View contentView =getLayoutInflater().inflate( R.layout.layout_detail_traffic_item, null);
PopupWindow popWnd = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
// 设置背景
popWnd.setBackgroundDrawable(new BitmapDrawable());
// 需要设置一下此参数,点击外边可消失
popWnd.setOutsideTouchable(true);
//获取选项,以便下边监听
TextView textDay = (TextView)contentView.findViewById(R.id.detail_traffic_day);
TextView textWeek = (TextView)contentView.findViewById(R.id.detail_traffic_week);
TextView textMonth = (TextView)contentView.findViewById(R.id.detail_traffic_month);
textDay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//做你想做的事
}
});
textWeek.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//做你想做的事
}
});
textMonth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//做你想做的事
}
});
//显示在某控件的下方
popWnd.showAsDropDown(v);
亲测很好用,比popupmenu好用多了,这个还可以随意设置大小。有什么不懂的可以留言给我,我会在第一时间回复。。。。。
- PopupWindow弹窗详解以及相关方法说明
- Popupwindow的showAsDropDown方法详解
- webservice以及相关概念说明
- PopupWindow相关
- Android之弹窗 PopupWindow简单使用详解
- PopUpWindow详解
- PopupWindow 详解
- PopupWindow详解
- springMVC详解以及注解说明
- PopupWindow---Android PopupWindow弹窗教程
- PopupWindow的使用以及ArrayAdatper.notifyDataSetChanged()无效详解
- PopupWindow的使用以及ArrayAdatper.notifyDataSetChanged()无效详解
- PopupWindow的使用以及ArrayAdatper.notifyDataSetChanged()无效详解
- PopupWindow的使用以及ArrayAdatper.notifyDataSetChanged()无效详解
- PopupWindow的使用以及ArrayAdatper.notifyDataSetChanged()无效详解
- PopupWindow的使用以及ArrayAdatper.notifyDataSetChanged()无效详解
- iftop 安装以及相关参数及说明
- 用户、组以及相关文件说明
- 汇编语言: 从键盘上输入 2 个一位数,求出它们的和(假设和不超过 1 位)。
- K-Means C实现(基于iris数据)
- 根据旋转矩阵(roational matrix)计算三个坐标轴的旋转角度
- Ue4 BluePrint蓝图实现镜头(视角)切换及摆动范围(三)
- 法线纹理实现过程问题记录
- PopupWindow弹窗详解以及相关方法说明
- 正则表达式简介
- Linux进程管理命令
- 有序表归并算法
- 热修复框架AndFix【源码阅读】
- C#泛型学习
- 汇编语言: 试编写一段程序,从键盘接收一个四位的十六进制数,并在终端上显示与它等值的二 进制数。
- 5-27
- 数据库设计基础原则