20150604_Andriod 窗体PopupWindow动画
参考地址: http://www.open-open.com/lib/view/open1378720752084.html
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0702/1627.html
/////////////////////////////////////////////////////////////////////
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);
}
}
/////////////////////////////////////////////////////////////////////
style.xml如下:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light" />
<style name="popupWindowAnimation" mce_bogus="1" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/enter</item>
<item name="android:windowExitAnimation">@anim/exit</item>
</style>
</resources>
enter.xml动画如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- android:fromYDelta:动画开始的点离当前View X坐标上的差值 -->
<!-- 利用100%p表示该动画在当前View的最下方 -->
<set
xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1500"
android:fromYDelta="100%p"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="0" />
</set>
exit.xml动画如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- Alpha=1.0表示不透明,Alpha=0.0表示透明 -->
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator" >
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:toAlpha="0.0"
/>
</set>
/////////////////////////////////////////////////////////////////////
PopupWindow的动画
很多时候我们把PopupWindow用作自定义的菜单,需要一个从底部向上弹出的效果,这就需要为PopupWindow添加动画。
设置动画的方法:
1.public void setAnimationStyle(int animationStyle)
2.在res/value/styles.xml添加一个sytle
3.在工程res下新建anim文件夹,在anim文件夹先新建两个xml文件 :enter.xml, exit.xml
/////////////////////////////////////////////////////////////////////
20150604_Andriod 窗体PopupWindow动画的更多相关文章
- 20150604_Andriod 窗体PopupWindow
package com.example.test1; import android.support.v7.app.ActionBarActivity;import android.os.Bundle; ...
- popUpWindow 动画无法超出窗体的解决方案
popupWindow 做动画时,当要求有一个放大动画时,动画无法超出窗体,给人的感觉是只有内容在放大,窗体不动. 这是由于窗口大小固定的原因,解决方案是加大popUpwindow的 大小. 一个比较 ...
- 自定义PopupWindow动画效果
public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...
- Android 自定义PopupWindow动画效果
public class RollActivity extends Activity { private View view; private Button btn; private PopupWin ...
- Android初级教程以动画的形式弹出窗体
这一篇集合动画知识和弹出窗体知识,综合起来以动画的形式弹出窗体. 动画的知识前几篇已经做过详细的介绍,可翻阅前面写的有关动画博文.先简单介绍一下弹出窗体效果的方法: 首先,需要窗体的实例:PopupW ...
- 【C#】窗体动画效果
通过调用API可以实现C#窗体的动画效果,主要调用user32.dll的行数AnimateWindow 1.函数申明 [System.Runtime.InteropServices.DllImport ...
- PopupWindow设置动画效果
创建popupwindow的方法 Button menu; private void showPopupWindow() { //设置contentView float density = Densi ...
- 【补间动画示例】Tweened Animation
代码中定义动画示例 public class MainActivity extends ListActivity </integer> 常用的Activity转场动画中的补间动画 publ ...
- android:PopupWindow的使用场景和注意事项
1.PopupWindow的特点 借用Google官方的说法: "A popup window that can be used to display an arbitrary view. ...
随机推荐
- Excel公式无法重算,暂无法解决
一份复杂的excel报表,某些单元格是用求和公式算出来的值,但生成之后,用excel打开,无法显示公式结果,按F9也没有用,只能在单元格公式双击后回车才会显示.而在WPS2010按F9就可以重算,WP ...
- 通用窗口类 Inventory Pro 2.1.2 Demo1(下续篇 ),物品消耗扇形显示功能
本篇想总结的是Inventory Pro中通用窗口的具体实现,但还是要强调下该插件的重点还是装备系统而不是通用窗口系统,所以这里提到的通用窗口类其实是通用装备窗口类(其实该插件中也有非装备窗口比如No ...
- Tomcat系列之Java技术详解
一.概述 1.前言 在前面几篇博客中,我们和大家说了负载均衡器服务器.Web服务器.反向代理服务器.缓存服务器,从这篇博客开始我们和大家说说应用程序服务器,对于上述内容不了解的博友可以去参考一下我们前 ...
- FB面经prepare: Task Schedule
每种task都有冷却时间,比如task1执行后,要经过interval时间后才能再次执行,求总共所需时间. 用HashMap保存每一个task的下一次可以开始执行的最早时间 package TaskS ...
- Codeforce Round #225 Div2
这回的C- -,弄逆序,我以为要弄个正的和反的,没想到是等价的,弄两个还是正确的,结果我又没注意1和0只能指1个方向,结果弄了4个,取了4个的最小值就错了,自己作死没弄出来...,后面又玩去了...哎 ...
- DO.NET操作数据库
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- redis数据库使用测试
注:java spring data redis内置了几种redis序列化机制.JdkSerializationRedisSerializer最高效.有关序列化更详细的介绍-http://www.my ...
- jquery遍历对象,数组,集合
1.jquery 遍历对象 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTM ...
- android环境搭建——工欲善其事,必先利其器 2
前两天鼓捣android, 搭建环境,不想麻烦就用了 adt-bundle-windows-x86-20140702. rar , 起个模拟器哇塞,太爽了. 出去转一圈唠会回来正好启动成功!有个网友 ...
- Yii框架,在页面输出执行sql语句,方便调试
1.下载yiidebugtb,并且放入到 application.extensions.yiidebugtb 目录 2.修改main.php,加入如下代码: 'log'=>array( 'cla ...