20150604_Andriod 窗体PopupWindow
package com.example.test1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
////////////////////////////
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
//import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
//import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.Toast;
////////////////////////////
public class PopupWindow2 extends ActionBarActivity {
////////////////////////////
private Button button;
private Button button1;
private Button button2;
private Button button3;
private Button button4;
private View popupWindowView;
private PopupWindow popupWindow;
private LayoutInflater inflater;
////////////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popup_window2);
////////////////////////////
button=(Button) findViewById(R.id.button_m);
button.setOnClickListener(new ButtonOnClickListener());
////////////////////////////
}
////////////////////////////
private class ButtonOnClickListener implements OnClickListener{
public void onClick(View v) {
inflater=(LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
popupWindowView=inflater.inflate(R.layout.activity_popup_window_sub, null);
popupWindow=new PopupWindow(popupWindowView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,true);
//必须要有这句否则弹出popupWindow后监听不到Back键
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAtLocation(findViewById(R.id.button_m), Gravity.NO_GRAVITY, 0, 0);
//让popupWindow获得焦点
popupWindow.setFocusable(true);
//设置动画
//popupWindow.setAnimationStyle(R.style.popupWindowAnimation);
popupWindow.update();
//popupWindow中按钮的处理
button1=(Button) popupWindowView.findViewById(R.id.button1);
button2=(Button) popupWindowView.findViewById(R.id.button2);
button3=(Button) popupWindowView.findViewById(R.id.button3);
button4=(Button) popupWindowView.findViewById(R.id.button4);
button1.setOnClickListener(new ButtonsOnClickListener());
button2.setOnClickListener(new ButtonsOnClickListener());
button3.setOnClickListener(new ButtonsOnClickListener());
button4.setOnClickListener(new ButtonsOnClickListener());
}
}
private class ButtonsOnClickListener implements OnClickListener {
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
//System.out.println("点击了按钮1");
Toast.makeText(getApplicationContext(), "提示:点击了按钮1,点击窗口外部关闭窗口!",
Toast.LENGTH_SHORT).show();
break;
case R.id.button2:
System.out.println("点击了按钮2");
break;
case R.id.button3:
System.out.println("点击了按钮3");
break;
case R.id.button4:
//System.out.println("点击了按钮4");
popupWindow.dismiss(); // 关闭窗口
break;
default:
break;
}
}
}
//监听Back事件
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode==KeyEvent.KEYCODE_BACK) {
if (popupWindow!=null&&popupWindow.isShowing()) {
popupWindow.dismiss();
} else {
//MainActivity.this.finish();
PopupWindow2.this.finish();
}
}
return super.onKeyDown(keyCode, event);
}
////////////////////////////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.popup_window2, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
//////////////////////////////////////////////////////////////
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test1.PopupWindow2" >
<Button
android:id="@+id/button_m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="test" />
</RelativeLayout>
//////////////////////////////////////////////////////////////
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test1.PopupWindow_sub" >
<LinearLayout
android:id="@+id/linerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
>
<Button
android:id="@+id/button1"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Button1"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
<Button
android:id="@+id/button2"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Button2"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
<Button
android:id="@+id/button3"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Button3"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
<Button
android:id="@+id/button4"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Button4"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dip"
/>
</LinearLayout>
</RelativeLayout>
//////////////////////////////////////////////////////////////
20150604_Andriod 窗体PopupWindow的更多相关文章
- 20150604_Andriod 窗体PopupWindow动画
参考地址: http://www.open-open.com/lib/view/open1378720752084.html http://www.jcodecraeer.com/a/anzhuoka ...
- Android popupwindow 失去焦点或者点击空白区域时消失的解决方法
先来看下Android API 的这个Methods: public void setOutsideTouchable (boolean touchable) Controls whether the ...
- popUpWindow 动画无法超出窗体的解决方案
popupWindow 做动画时,当要求有一个放大动画时,动画无法超出窗体,给人的感觉是只有内容在放大,窗体不动. 这是由于窗口大小固定的原因,解决方案是加大popUpwindow的 大小. 一个比较 ...
- PopupWindow 防微信弹出右 侧窗体(继承PopupWindow )
1, pop自定义 public class SelectPicPopupWindow extends PopupWindow { private Button btn_take_photo, btn ...
- PopupWindow 从底部弹出窗体
第一步 : 初始化PopupWindow private void initPop() { if (view == null) { // 照片 view = View.inflate(Registe ...
- PopupWindow --- 弹出底部窗体
第一步 : 布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...
- 仿QQ空间根据位置弹出PopupWindow显示更多操作效果
我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: ...
- popupwindow的基本使用以及基本动画效果
1.创建一个popupwindow view的布局文件自己写一个就好了,这里就不说了 View view= LayoutInflater.from(context).inflate(R.layout. ...
- webview加载h5,关闭activity时,窗体泄露问题
问题描述: webview加载一个含有input控件的html页面,当点击input控件是回调app的closepage方法[closepage中只有一个finish操作],出现窗体泄露问题. 分析: ...
随机推荐
- Java基础之读文件——使用通道读取混合数据2(ReadPrimesMixedData2)
控制台程序,本例读取Java基础之写文件部分(PrimesToFile2)写入的Primes.txt. 方法二:设置一个任意容量的.大小合适的字节缓冲区并且使用来自文件的字节进行填充.然后整理出缓冲区 ...
- linux:档案与目录管理
几个常见的目录处理命令: cd(change directory):变更目录 pwd(print working directory):显示当前目录[目录为连结档,则只显示连结档的路径]([-P]不以 ...
- C++Primer 第十七章
//1.当我们希望将一些数据组合成单一对象,但又不想麻烦地定义一个新的数据结构来表示这些数据的时候,tuple非常有用.其和其伴随类型和函数都定义在头文件tuple中,声明在命名空间std中. tup ...
- C++Primer 第十六章
//1.模板定义以关键字template开始,后跟一个模板参数列表,此列表不能为空.编译器用推断出的模板参数来实例化一个特定版本的函数.类型参数前必须使用class或者typename(推荐使用typ ...
- JAVA-环境部分
JAVA环境 1.jdk 1.从Oracle网站下载安装包(32位.64位) 2.安装目录不用中文或空格 3.配置环境变量 1作用:提供jdk存放位置信息 2系统环境变量 1增加-JAVA_HOME= ...
- 监控linux服务器网卡流量
监控linux服务器网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入:高级运维工程师之路 598432640 前言:众所周知,我们安装zabbix服务器 ...
- Codeforce Round #217 Div2
e,妈蛋,第二题被hack了 没理解清题意,- -居然也把pretest过了,- -# A: 呵呵! B:包含任意一个子集的输出NO!,其他输出YES! C:贪心额,类似上次的Topcoder的500 ...
- Struts2.3+Spring+iBatis 初学之问题判断
小白接下来将会总结下我再学习Spring的学习过程中(ssi框架)中遇到的问题,以后会不断的进行更新. 最容易犯的问题,就是声明bean的时候,属性引用其他声明的bean的时候,name没有进行好对应 ...
- php CI框架目录结构及运行机制
CI目录结构 CI主要组成部分为,application(应用文件夹).system(系统文件夹)和index.php入口文件. 应用文件夹中主要是存放控制器.模型和视图等,系统文件夹中主 ...
- Arm环境搭建-基于博创科技(CentOS7.0系统安装篇1)
CentOs 7.0安装和基本命令篇 目的:学习基本的linux命令,熟悉linux操作系统,安装linux.(安装过5.5,6.3并不是安装一帆风顺的,多次安装,有个10次多吧,基本会 ...