UI组件之PopupWindow
来源:互联网 发布:中国房地产统计数据库 编辑:程序博客网 时间:2024/05/20 09:47
UI组件之PopupWindow
PopupWindow简介
PopupWindow也是对话框的一种,它和AlertDialog的不同之处就是AlertDialog的位置是固定的,而PopupWindow的位置是可以任意设置的
PopupWindow的创建
PopupWindow popupWindow = new PopupWindow(参数1, 参数2, 参数3);
参数1:PopupWindow的内容,也就是PopupWindow的布局
参数2:PopupWindow的宽
参数3:PopupWindow的高
创建一个PopupWindow
主界面布局代码
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="弹出一个Popup窗口" /></RelativeLayout>
PopupWindow布局代码
<?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" > <ImageView android:src="@drawable/baby0" android:layout_width="400dp" android:layout_height="400dp" /> <Button android:id="@+id/btn_close" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="关闭" /></LinearLayout>
Activity代码
package com.shake.day11_android_5;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.view.WindowManager;import android.widget.PopupWindow;public class MainActivity extends AppCompatActivity implements View.OnClickListener { private PopupWindow popupWindow; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.button).setOnClickListener(this); //装载PopupWindow的布局 View popup_view = LayoutInflater.from(this).inflate(R.layout.popup_layout, null); //创建PopupWindow对象,PopupWindow的宽度和屏幕宽度一样 popupWindow = new PopupWindow(popup_view, WindowManager.LayoutParams.MATCH_PARENT, 1500); //设置动画属性 popupWindow.setAnimationStyle(android.R.style.Animation_Translucent); //关闭PopupWindow的按钮监听事件 popup_view.findViewById(R.id.btn_close).setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button: //以下拉方式显示 popupWindow.showAsDropDown(v); break; case R.id.btn_close: //关闭PopupWindow popupWindow.dismiss(); break; } }}
效果
点击了弹出按钮之后,再点击关闭按钮PopupWindow就会消失
0 0
- UI组件之PopupWindow
- Android UI 之 PopupWindow
- android组件之PopupWindow
- [阶段二]Android UI PopupWindow组件
- UI组件之Spinner
- UI组件之AutoCompleteTextView
- UI组件之TimePiker
- UI组件之ExpandableListView
- UI组件之Notification
- vaadin之UI组件
- Android UI之TextView组件
- Android UI之CheckBox组件
- Android UI 之ListView组件
- Android UI 之Spinner组件
- Android四大组件之UI
- UI组件之UIWebView学习
- #Android#UI组件之spinner
- Android UI之在popupwindow中获取控件注意问题
- 统计学习方法第二章笔记——感知机
- js构造函数学习笔记
- 抽中概率 php
- android 自定义view实现 游戏血量条。带减血缓冲,颜色变化。
- SpringMVC拦截器学习
- UI组件之PopupWindow
- POJ 1743 Musical Theme 后缀数组+二分
- 使用Fiddler对Android App进行抓包的步骤详解
- java I/O学习笔记3 ---NIO
- em和rem的区别
- listview左右滑动item效果
- BZOJ(本校) 2525 公约数 - 莫比乌斯反演
- apache工作模式详解
- Cannot find a valid baseurl for repo: base/7/x86_64