popupwindow的学习
来源:互联网 发布:mpp文件打开软件 编辑:程序博客网 时间:2024/05/23 13:02
源地址:http://blog.csdn.net/xyz_lmn/article/details/6906286
自定义的一个弹窗,学习学习。
MainActivity.java:
package com.example.li.popupwindow;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.Gravity;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.PopupWindow;public class MainActivity extends AppCompatActivity implements View.OnClickListener{ View view; PopupWindow pop; Button btnShowAsDrawDown; Button btnShowAsDrawDown1; Button btnShowAtLocation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.popup_activity); btnShowAsDrawDown = (Button) findViewById(R.id.btnShowAsDrawDown); btnShowAsDrawDown.setOnClickListener(this); btnShowAsDrawDown1 = (Button) findViewById(R.id.btnShowAsDrawDown1); btnShowAsDrawDown1.setOnClickListener(this); btnShowAtLocation = (Button) findViewById(R.id.btnShowAt); btnShowAtLocation.setOnClickListener(this); initPopupWindow(); } private void initPopupWindow() { view = this.getLayoutInflater().inflate(R.layout.popup_window, null); pop = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ); pop.setOutsideTouchable(true); Button btnpop = (Button) view.findViewById(R.id.btn_pop); btnpop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pop.dismiss(); } }); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.btnShowAsDrawDown: if(pop.isShowing()){ pop.dismiss(); }else{ pop.showAsDropDown(v); } break; case R.id.btnShowAsDrawDown1: if(pop.isShowing()){ pop.dismiss(); }else{ pop.showAsDropDown(v, 0, -160); } break; default: if(pop.isShowing()){ pop.dismiss(); }else{ pop.showAtLocation(findViewById(R.id.main), Gravity.CENTER_HORIZONTAL, 0, 0 ); } break; } }}
popup_activity.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="pop demo!" /> <Button android:id="@+id/btnShowAsDrawDown" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Show as drawndown(one parameter)" /> <Button android:id="@+id/btnShowAsDrawDown1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Show as drawndown(three parameters)" /> <Button android:id="@+id/btnShowAt" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Show At Location" /></LinearLayout>
popup_window.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="horizontal" android:background="#a00ddddd" android:gravity="center" > <Button android:id="@+id/btn_pop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dip" android:text="Close" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
0 0
- popupwindow的学习
- PopupWindow学习
- PopupWindow学习
- PopupWindow学习
- PopupWindow学习总结
- 学习笔记 popupwindow
- PopupWindow学习总结
- PopupWindow学习大全
- android学习之popupWindow
- Android学习之PopupWindow
- PopupWindow学习整理
- PopupWindow学习笔记
- Android学习之PopupWindow
- android学习笔记---63-PopupWindow,泡泡窗口的实现
- Android开发技术学习之popupwindow的弹窗实现
- Android开发技术学习之popupwindow的弹窗实现
- Android PopupWindow的使用
- Android PopupWindow的使用
- 责任链模式(java语言实现)
- javaweb基于内容的图片搜索引擎(4)_前台检索以及结果
- vertical-align: middle垂直居中
- web开发中表单的验证问题
- 【静下心学习Unity】学习笔记 (三)Unity Physics - Hinge Joint(铰链关节) 实现门的功能
- popupwindow的学习
- Maven学习记录(一)--IDEA下环境配置
- SQL中的limit
- c++第三次实验-1
- 关于this
- 【珍藏】linux 同步IO: sync、fsync与fdatasync
- c++作业03
- struts2标签又显示不出来
- 建立一个学生类及其相应对象