仿微信 个人头像修改 popPopupWindow实现Menus从底部弹出
2016-10-21 12:55
471 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。
先看效果图:
代码:自定义一个类 继承PopupWindows
[java]
view plain
copy
print?
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() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dismiss();
}
});
// 导入布局
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() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int 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;
}
});
}
}
单击弹出菜单:
[java]
view plain
copy
print?
private void showPopMenu() {
// TODO Auto-generated method stub
popMenus = new PhotoPopupWindows(this, myMenusOnClick);
popMenus.showAtLocation(this.findViewById(R.id.ll_person_info),
Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
}
动画效果:
fade_in:
[java]
view plain
copy
print?
<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:
[java]
view plain
copy
print?
<translate
android:duration="200"
android:fromYDelta="0"
android:toYDelta="50%p" />
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
先看效果图:
代码:自定义一个类 继承PopupWindows
[java]
view plain
copy
print?
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() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dismiss();
}
});
// 导入布局
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() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int 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;
}
});
}
}
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() { @Override public void onClick(View v) { // TODO Auto-generated method stub dismiss(); } }); // 导入布局 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() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub int 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; } }); } }
单击弹出菜单:
[java]
view plain
copy
print?
private void showPopMenu() {
// TODO Auto-generated method stub
popMenus = new PhotoPopupWindows(this, myMenusOnClick);
popMenus.showAtLocation(this.findViewById(R.id.ll_person_info),
Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
}
private void showPopMenu() { // TODO Auto-generated method stub popMenus = new PhotoPopupWindows(this, myMenusOnClick); popMenus.showAtLocation(this.findViewById(R.id.ll_person_info), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); }
动画效果:
fade_in:
[java]
view plain
copy
print?
<translate
android:duration="200"
android:fromYDelta="100%p"
android:toYDelta="0" />
<alpha
android:duration="200"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
<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:
[java]
view plain
copy
print?
<translate
android:duration="200"
android:fromYDelta="0"
android:toYDelta="50%p" />
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
<translate android:duration="200" android:fromYDelta="0" android:toYDelta="50%p" /> <alpha android:duration="200" android:fromAlpha="1.0" android:toAlpha="0.0" />
相关文章推荐
- 仿微信 个人头像修改 popPopupWindow实现Menus从底部弹出
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- ios实现底部PopupWindow的示例代码(底部弹出菜单)
- Android PopupWindow实现右侧、左侧和底部弹出菜单
- PopupWindow实现右侧、左侧和底部弹出菜单
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- iOS实现底部弹出PopupWindow效果 iOS改变背景透明效果
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
- Android PopupWindow实现从顶部弹出下拉菜单左、中、右
- Android之PopupWindow类似微信右上角的弹出菜单
- 实现点击menu键popupWindow显示和消失,模仿微信更多按钮
- android中仿微信popwindow弹出方式
- android PopupWindow 和 Activity弹出窗口实现方式
- Android PopupWindow 实现自定义弹出层
- 仿微信长按弹出popwindow效果
- 二进制数据流方式实现 个人头像的读取、上传、修改------善良公社项目