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
- PopupWindow弹窗demo
- PopupWindow小Demo
- android PopupWindow demo
- Popupwindow 完美demo
- 简单的popupWindow的demo
- PopupWindow弹窗
- 弹窗popupwindow
- PopupWindow弹窗
- android PopupWindow重写系统菜单Demo
- 一个测试ok的popupwindow demo
- 【Android开发日记】Popupwindow 完美demo
- 第十章,PopupWindow简易demo(Android)
- PopupWindow的二级菜单的简单demo
- Android PopupWindow显示在控件上方或者下方(demo)
- Android封装之PopupWindow(一) (带demo)
- Android弹窗PopupWindow
- Android PopupWindow弹窗
- popupwindow
- asp.net课后总结(4)
- c语言strcpy函数的漏洞
- 6174问题
- 汉诺塔
- 设计模式(4)-对象创建型模式-Prototype模式
- PopupWindow弹窗demo
- 拷贝文件经典代码
- Android Loaders(一)概述
- Pow(x, n)
- [Linux内存]linux内存学习(五)——伙伴系统
- 定时跳转
- DESTOON邮件发送设置
- Mutihop on ssh
- Linux的I2C驱动讲解