仿微信 个人头像修改 popPopupWindow实现Menus从底部弹出

来源:互联网 发布:ssh使用的端口号是 编辑:程序博客网 时间:2024/05/17 12:25

先看效果图:



代码:自定义一个类 继承PopupWindows

package com.yuan.keyanhelper.view;import io.vov.vitamio.activity.InitActivity;import java.util.List;import com.example.keyanhelper.R;import com.example.keyanhelper.R.layout;import android.app.Activity;import android.content.Context;import android.graphics.drawable.ColorDrawable;import android.view.LayoutInflater;import android.view.MotionEvent;import android.view.View;import android.view.View.OnClickListener;import android.view.View.OnTouchListener;import android.view.ViewGroup.LayoutParams;import android.widget.Button;import android.widget.PopupWindow;import android.widget.AdapterView.OnItemClickListener;public class PhotoPopupWindows extends PopupWindow {private View mMenuView; // PopupWindow 菜单布局private Context context; // 上下文参数private OnClickListener myOnClick; // PopupWindow 菜单 空间单击事件public PhotoPopupWindows(Activity context, OnClickListener myOnClick) {super(context);this.context = context;this.myOnClick = myOnClick;Init();}private void Init() {// TODO Auto-generated method stub// PopupWindow 导入LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);mMenuView = inflater.inflate(R.layout.popitem_alter_icon, null);Button btn_camera = (Button) mMenuView.findViewById(R.id.btn_alter_pic_camera);Button btn_photo = (Button) mMenuView.findViewById(R.id.btn_alter_pic_photo);Button btn_cancel = (Button) mMenuView.findViewById(R.id.btn_alter_exit);btn_camera.setOnClickListener(myOnClick);btn_cancel.setOnClickListener(myOnClick);btn_photo.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubdismiss();}});// 导入布局this.setContentView(mMenuView);// 设置动画效果this.setAnimationStyle(R.style.AnimationFade);this.setWidth(LayoutParams.FILL_PARENT);this.setHeight(LayoutParams.WRAP_CONTENT);// 设置可触this.setFocusable(true);ColorDrawable dw = new ColorDrawable(0x0000000);this.setBackgroundDrawable(dw);// 单击弹出窗以外处 关闭弹出窗mMenuView.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {// TODO Auto-generated method stubint height = mMenuView.findViewById(R.id.ll_pop).getTop();int y = (int) event.getY();if (event.getAction() == MotionEvent.ACTION_UP) {if (y < height) {dismiss();}}return true;}});}}

单击弹出菜单:

private void showPopMenu() {// TODO Auto-generated method stubpopMenus = new PhotoPopupWindows(this, myMenusOnClick);popMenus.showAtLocation(this.findViewById(R.id.ll_person_info),Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);}



动画效果:

fade_in:

  <translate        android:duration="200"        android:fromYDelta="100%p"        android:toYDelta="0" />    <alpha        android:duration="200"        android:fromAlpha="0.0"        android:toAlpha="1.0" />

fade_out:

 <translate        android:duration="200"        android:fromYDelta="0"        android:toYDelta="50%p" />    <alpha        android:duration="200"        android:fromAlpha="1.0"        android:toAlpha="0.0" />




0 0