PopupWindow弹窗demo

来源:互联网 发布:销售报表数据分析 编辑:程序博客网 时间:2024/06/02 13:35

main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:gravity="center"    android:orientation="vertical" >    <Button        android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="pop" /></LinearLayout>


 

自定义View

pop_view.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:gravity="center"    android:orientation="vertical" >    <Button        android:id="@+id/button_popupe"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_margin="10dip"        android:text="pop,pop" >    </Button></LinearLayout>


 

anim文件下自定义动画

fipper_in.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="1000"        android:fromYDelta="100%p"        android:toYDelta="0" />    <alpha        android:duration="1000"        android:fromAlpha="0.0"        android:toAlpha="1.0" /></set>


 

fipper_out.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="1000"        android:fromYDelta="0"        android:toYDelta="100%p" />    <alpha        android:duration="1000"        android:fromAlpha="1.0"        android:toAlpha="0.0" /></set>


ActivityMain

package com.android;import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup.LayoutParams;import android.view.animation.AnimationUtils;import android.widget.Button;import android.widget.PopupWindow;import android.widget.ViewFlipper;public class ActivityMain extends Activity {//定义PopupWindowprivate PopupWindow popup;//定义PopupWindow动画private ViewFlipper mViewFlipper;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        // 创建动画mViewFlipper = new ViewFlipper(this);mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.flipper_in));mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.flipper_out));//获取自定义的pop_view,因为pop_view.xml没有设置setContentView方法,所以不能用findViewById方法获取对象LayoutInflater mLayoutInflater = LayoutInflater.from(getApplicationContext());View pop_view = mLayoutInflater.inflate(R.layout.pop_view, null);mViewFlipper.addView(pop_view);mViewFlipper.setFlipInterval(3000);// 创建Popuppopup = new PopupWindow(mViewFlipper, LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);popup.setBackgroundDrawable(getResources().getDrawable(R.drawable.pop_bg));popup.setFocusable(true);popup.update();//开启pop的按钮Button btn = (Button)this.findViewById(R.id.button1);btn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {if (popup != null) {if (popup.isShowing()) {popup.dismiss();} else {//相对与某个控件的位置    popup.showAtLocation(v,Gravity.BOTTOM, 0, 0);    //播放动画    mViewFlipper.startFlipping();}}}});    }}


点击pop按钮即可出现下面pop.pop弹窗。

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 第章母亲播种危险期怀孕 儿子今晚后妈随便你怎么弄说说 同学说要看我骑他妈我说可以 荒村野性全文阅读目录 小成和后妈全文免费阅读文章 小诚和后妈全文免费阅读 娘亲在玉米地河边 我和娘亲玉米 娘亲给儿生个娃大结局 在玉米地插娘亲短文 在玉米地插娘亲电影 王来地里与娘激战2 在玉米地插娘亲播放 孩子别谢了我是你妈 臭小子 别急妈咪又不是不给你 粉嫩娘亲全文阅读全文 你的好粗妈v好痛 乡村孽缘上了王雪琴101一0 乡村小神医之情缠玉米地 乡村孽缘长篇小说全文免费阅读 乡村孽缘王雪琴怀孕是第几章 桃花村傻牛李大根 拨出来你爸要来 一个山村全家小说全集 乡村孽缘胡秀`小说全集 儿子小点声别让你爸听见长篇小说 胡秀英全文费阅读全文 儿子小声点别让你爸听见小说 乡村浪子的孽缘大伯母 畜牲别让你爸听见在线小说阅读 胡秀英乡全文免费阅读 婶的肥田全文免费阅读 乡村孽缘 王雪琴 熟花母芬芳泌蜜全文阅读 中文字字幕23页在线 单身娘亲有肥田 中文字字幕125页 中文字幕天堂网 中文字126幕中文字页幕 学生的母亲3字幕中文翻译 中幕文字36页