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. ...
随机推荐
- Sql清理日志文件
场景: 我们导入MR数据时发现磁盘空间不够用了,导致的结果就是我们的程序很可能会抛出异常了,我们需要导入数据的时候进行日志瘦身. 问1:导入数据的时候,瘦身是否会造成数据库的异常? DBA提供解决方案 ...
- Undefined symbols “_OBJC_CLASS_$_XXX” 问题
解决方法是点击工程,在targets界面中找到Build Phases,根据提示信息“XXX”来判断缺少什么文件,一般如果缺少自定义的文件,XXX会是缺少的类名,那么就在Complie Sources ...
- 搭建企业cacti服务器
搭建企业cacti服务器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 今天搭建了cacti,为了方便监控我的交换机~因为查了很多zabbix的资料关于监控交换机的教程~我都屡屡失 ...
- [转] java编程规范
原文链接: 资料推荐--Google Java编码规范 之前已经推荐过Google的Java编码规范英文版了: http://google-styleguide.googlecode.com/svn/ ...
- CSS_03_04_CSS伪元素选择器
第01步:编写css代码:wei.css @charset "utf-8"; /* 伪元素选择器 :状态 效果顺序:L V H A */ a:link.lin_01{/*超链接,未 ...
- paper 54 :图像频率的理解
我一直在思考一个问题,图像增强以后,哪些方面的特征最为显著,思来想去,无果而终!翻看了一篇知网的paper,基于保真度(VIF)的增强图像质量评价,文章中指出无参考质量评价,可以从三个方面考虑:平均梯 ...
- scan cell
scan cell有两种不同的input: 1)data input:由电路的combinational logic驱动: 2)scan input:由另一个scan cell驱动,从而形成scan ...
- ajax中网页传输(二)JSON——下拉列表显示练习
以json返回数据类型显示“民族下拉列表” 第一:body页面显示部分 <title>JSON下拉显示Nation表中的数据</title> <script src=&q ...
- 《zw版·Halcon-delphi系列原创教程》 邮票艺术品自动分类脚本
<zw版·Halcon-delphi系列原创教程> 邮票艺术品自动分类脚本 邮票艺术品自动分类脚本,是个综合应用,有不同尺寸图像的自动识别.区域分割 还有作品附近文字的自动分割 此类项目, ...
- 《zw版·delphi与halcon系列原创教程》hello,zw
<zw版·delphi与halcon系列原创教程>hello,zw 按惯例,第一个程序是‘hello’ 毕竟,Halcon是专业的图像库,所以我们就不用纯文本版的,来一个专业版.Halco ...