- 浏览: 121868 次
文章分类
- 全部博客 (65)
- web验证码 (0)
- 工具类 (4)
- android基础 (17)
- android通信 (1)
- JFreeChart (1)
- java基础 (5)
- android控件 (4)
- FusionCharts (1)
- android Layout (1)
- json (2)
- HTTP协议 (1)
- cmd (1)
- struts (3)
- Spring (1)
- java网络编程 (3)
- Linux (1)
- DB (5)
- Open Source (1)
- css (0)
- javascript (7)
- jquery (0)
- Socket (1)
- ajax (1)
- 整合开发 (1)
- UDP协议 (1)
最新评论
-
hy18710385392:
亲:import com.nudms.server.nurse ...
java实现打印PDF文件解决方案 -
osacar:
MyPDFPrintPage这个类能提供下?
java实现打印PDF文件解决方案 -
井底之龙:
请问楼主定义的保存Button从开始到最后都没有从xml文件中 ...
Android之SharedPreferences的使用 保存用户设置 -
lohasle:
liangzb0614 写道你好,求一个MyPDFPrintP ...
java实现打印PDF文件解决方案 -
liangzb0614:
你好,求一个MyPDFPrintPage 类!拜托了liang ...
java实现打印PDF文件解决方案
用的豌豆荚截图,本来是个动画的,每个过程都有几张,大概就是要实现这个效果,初始状态只有一个Button,当点击show的时候,另外一个页面从底部慢慢升起来,直到覆盖到上一个页面,注意这里不是启用另一个Activity,是用的PopupWindow,当点击dismiss的时候,又慢慢消失。。。这种效果看上去不错,PopupWindow上面可以添加想要添加的控件,比如ListView(注意,如果添加ListView的话,当它弹出来之后,按back键不起作用,它获取不了监听,其余的非ListView控件可以,这里添加了个Button ),下面贴出代码
这是主类MainActivity.java
package com.test.popupwindow; 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.widget.Button; import android.widget.LinearLayout.LayoutParams; import android.widget.PopupWindow; publicclass MainActivity extends Activity { /** Called when the activity is first created. */ boolean flag =false; PopupWindow popupWindow; @Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } publicvoid init() { Button btn_show = (Button) findViewById(R.id.btn_show); LayoutInflater inflater = LayoutInflater.from(this); View layout = inflater.inflate(R.layout.popup, null); popupWindow =new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); Button btn_dismiss = (Button) layout.findViewById(R.id.btn_dismiss); btn_dismiss.setOnClickListener(new OnClickListener() { @Override publicvoid onClick(View v) { // TODO Auto-generated method stub openMenu(); } }); btn_show.setOnClickListener(new OnClickListener() { @Override publicvoid onClick(View v) { // TODO Auto-generated method stub openMenu(); } }); } publicvoid btn_showOnClicked() { openMenu(); } publicvoid btn_dismissOnClicked() { openMenu(); } publicvoid openMenu() { if (!flag) { popupWindow.setAnimationStyle(R.style.PopupAnimation); popupWindow.showAtLocation(findViewById(R.id.btn_show), Gravity.NO_GRAVITY, 0, 0); popupWindow.setFocusable(true); popupWindow.update(); flag =true; } else { popupWindow.dismiss(); popupWindow.setFocusable(false); flag =false; } } }
布局文件main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/layout" > <Button android:id="@+id/btn_show" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="show" /> </RelativeLayout>
布局文件popup.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#cccccc" > <Button android:id="@+id/btn_dismiss" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="dismiss"/> </LinearLayout>
注意看在res文件夹下面新建了一个anim文件夹,里面要实现的动画页面,比如从哪个坐标移动到哪个坐标之类的,当然还可以定义其它的,这里只实现了Y坐标的移动
在anim文件夹下面建两个文件,一个是in.xml,另外一个是out.xml,意思一看就明白
in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator"> <translate android:fromYDelta="854" android:toYDelta="0" android:duration="1000"/> </set>
它表示Y的坐标从854(因为我的手机分辨率是850x480,摩托MB525)移动到0,时间为1秒
out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:interpolator="@android:anim/decelerate_interpolator" android:fromYDelta="0" android:toYDelta="854" android:duration="10000" /> </set>
有人给我反应说缺少style文件,我看了一下,确实是,当时发贴的时候漏掉了,现在补上
在values文件夹下面建一个styles.xml文件
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="PopupAnimation" parent="android:Animation" mce_bogus="1"> <item name="android:windowEnterAnimation">@anim/in</item> <item name="android:windowExitAnimation">@anim/out</item> </style> </resources>
本文转自:http://www.cnblogs.com/and_he/archive/2011/08/12/2136107.html
发表评论
-
Android 中OpenGL的使用
2013-06-18 22:48 2375android为openGL ES支持提供了GLSurface ... -
android 之GestureOverlayView手势识别
2013-05-28 00:18 2323android 之GestureOverlayView ... -
android 之ViewPager左右滑动切换界面
2013-05-26 23:49 2469这是谷歌官方给我们提供的一个兼容低版本安卓设备的软件包,里面包 ... -
Android之SharedPreferences的使用 保存用户设置
2013-05-18 18:56 2309SharedPreferences是Android平台上一个轻 ... -
android手机内存中的文件操作
2013-05-18 08:47 1277android为手机存储范围内的文件操作提供了openFile ... -
使用contentprovider共享生词本数据
2013-04-06 10:49 1143摘自李刚<疯狂android>备份学习使用 首先 ... -
contentprovider--读取写入联系人数据
2013-04-05 17:39 1577本文主要使用contentprovider实现读取写入联系人数 ... -
android读写XML
2013-01-08 11:08 955详细代码看附件! 布局文件: <RelativeL ... -
android检测网络是否正常
2012-05-17 23:18 1785按照惯例,先上图后代码 在实际开发中,尤其是在网络应用 ... -
Android Handler详解
2012-05-16 10:55 1363/*** * Handler的定义: ... -
android之OnScrollListener 下拉刷新
2012-05-12 20:47 2729先看看效果图吧 1.首先创建一个头部xml文件 < ... -
android之WebView的使用
2012-05-09 23:50 1192为了先体验一下效果,截了一个图 main.xml < ... -
android之OnGestureListener实现图片的左右滑动
2012-04-24 22:07 3350先来看看效果图吧 welcome_glide.xml ... -
android解析json(2)
2012-04-17 23:57 1418两种android解析json的例子 第一个事件是androi ... -
JSON在android中的应用(1)
2012-04-16 23:47 1254android框架已经为我们集成了解析json的包 先一个简 ... -
android实现淡入淡出欢迎界面
2012-03-03 21:34 4405本例子会实现想手机QQ和酷狗那样的淡入淡出的欢迎界面 im ...
相关推荐
具体使用请关注博客:http://blog.csdn.net/stoppig 查看《Android中popWindow弹出菜单的编写》这篇文章
android popupwindow 底部灰色背景
Android开发之PopupWindow实现弹窗
android中popupWindow使用案列。点击按钮,显示出菜单按钮。
很简单的入门材料,照着写一遍,效果会更好。
android自定义PopupWindow,实现类似微信弹框类别选项。
android 封装一个通用PopupWindow,避免重复造轮子,简化代码,方便管理。
Android Spinner PopupWindow 实现弹出框
Android PopupWindow与Activity之间的数据传递
Android: PopupWindow 上显示 ListView 并相应 Demo (仿QQ登录界面,待改进)
Android自定义PopupWindow日历 日期时间选择器 可自由搭配年月日时分显示,可以设置只显示年月日,不显示时分等,
Android之用PopupWindow实现弹出listview形式菜单.rar
Android弹窗实现之Popupwindow及DialogFragment。创建并实现PopupWindow布局 实现PopupWindow对象实例 设置PopupWindow背景、动画属性、控件实现及事件监听 显示PopupWindow及位置设定。
android通过使用popupwindow控件实现自定义menu菜单
Android之PopupWindow课程对应的代码
Android从屏幕底部滑动弹出PopupWindow,有动画效果,类似于sharesdk的分享页面滑动弹出效果。
android使用PopUpWindow自定义下拉框
NULL 博文链接:https://elingwange.iteye.com/blog/1613197
AS写的PopupWindow demo blog:http://blog.csdn.net/shenyuanqing/article/details/48136639
Android TV 开发有关PopupWindow的KeyListener