android 仿微信底部弹出菜单
2013-07-14 20:20
411 查看
最近在网上看了一些文章介绍使用PopupWindow实现 微信弹出菜单,于是乎自己也实现了一下,分享一下!
原理:主要是 popupWindow.setAnimationStyle(R.style.popuStyle);//设置 popupWindow 动画样式
运行效果截图
注意:popupWindow 的 showAtLocation(parent, gravity, x, y); 方法 第一个参数 parent 并不一定要求是 Activity 布局中的 根节点 元素,这里我传入了一个 Button
阅读官方文档中的说明
parent a parent view to get the
只是根据这个parent 获取 WindowToken 而已
popupWindow 动画样式
popup_anim_in.xml
popup_anim_out.xml
原理:主要是 popupWindow.setAnimationStyle(R.style.popuStyle);//设置 popupWindow 动画样式
运行效果截图
package com.example.test; import android.app.Activity; import android.graphics.drawable.BitmapDrawable; 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.widget.Button; import android.widget.LinearLayout; import android.widget.PopupWindow; public class MainActivity extends Activity implements OnClickListener { private PopupWindow popupWindow; private Button bt_popup; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findView(); } private void findView() { bt_popup = (Button) findViewById(R.id.bt_popup); bt_popup.setOnClickListener(this); } private void showPopupWindow() { View view = (LinearLayout) LayoutInflater.from(MainActivity.this) .inflate(R.layout.popmenu, null); Button bt_clear = (Button) view.findViewById(R.id.bt_clear); Button bt_exit = (Button) view.findViewById(R.id.bt_exit); bt_clear.setOnClickListener(this); bt_exit.setOnClickListener(this); if (popupWindow == null) { popupWindow = new PopupWindow(MainActivity.this); popupWindow.setBackgroundDrawable(new BitmapDrawable()); // popupWindow.setFocusable(true); // 设置PopupWindow可获得焦点 popupWindow.setTouchable(true); // 设置PopupWindow可触摸 popupWindow.setOutsideTouchable(true); // 设置非PopupWindow区域可触摸 popupWindow.setContentView(view); popupWindow.setWidth(LayoutParams.MATCH_PARENT); popupWindow.setHeight(LayoutParams.WRAP_CONTENT); popupWindow.setAnimationStyle(R.style.popuStyle); //设置 popupWindow 动画样式 } popupWindow.showAtLocation(bt_popup, Gravity.BOTTOM, 0, 0); popupWindow.update(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bt_popup: showPopupWindow(); break; case R.id.bt_exit: popupWindow.dismiss(); break; case R.id.bt_clear: popupWindow.dismiss(); break; default: break; } } }
注意:popupWindow 的 showAtLocation(parent, gravity, x, y); 方法 第一个参数 parent 并不一定要求是 Activity 布局中的 根节点 元素,这里我传入了一个 Button
阅读官方文档中的说明
parent a parent view to get the
android.view.View.getWindowToken()token from
只是根据这个parent 获取 WindowToken 而已
popupWindow 动画样式
<style name="popuStyle"> <item name="android:windowEnterAnimation">@anim/popup_anim_in</item> <item name="android:windowExitAnimation">@anim/popup_anim_out</item> </style>
popup_anim_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromXDelta="0" android:fromYDelta="100%p" android:toXDelta="0" android:toYDelta="0" /> </set>
popup_anim_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="300" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="0" android:toYDelta="100%p" /> </set>
相关文章推荐
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- Android仿微信底部菜单
- Android 实现底部弹出菜单
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android popwindow仿微信右上角弹出框,dialog底部显示
- Android 底部弹出Dialog(横向满屏模仿微信分享功能)
- android Activity实现从底部弹出或滑出选择菜单或窗口
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
- android PopupWindow底部弹出gridview菜单
- 微信小程序例子——使用action-sheet弹出小程序底部菜单
- Android自定义Dialogの仿ios系统底部菜单(自下而上弹出)
- Android PopupWindow实现微信右上角的弹出菜单
- android Activity实现从底部弹出或滑出选择菜单或窗口
- android AlertDialog用作底部弹出菜单
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- Android中软键盘弹出时底部菜单上移问题
- Android自定义PopWindow实现QQ、微信弹出菜单效果
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- Android中微信小程序开发之弹出菜单