注册

Android开发者你好~你还在用dialog????

 https://github.com/li-xiaojun/XPopup/



  • 内置几种了常用的弹窗,十几种良好的动画,将弹窗和动画的自定义设计的极其简单;目前还没有出现XPopup实现不了的弹窗效果。 内置弹窗允许你使用项目已有的布局,同时还能用上XPopup提供的动画,交互和逻辑封装。
  • UI动画简洁,遵循Material Design,在设计动画的时候考虑了很多细节,过渡,层级的变化
  • 交互优雅,实现了优雅的手势交互,智能的嵌套滚动,智能的输入法交互,具体看Demo
  • 适配全面屏,目前适配了小米,华为,谷歌,OPPO,VIVO,三星,魅族,一加全系全面屏手机
  • 自动监听Activity生命周期,自动释放资源。在Activity直接finish的场景也避免了内存泄漏
  • 很好的易用性,所有的自定义弹窗只需继承对应的类,实现你的布局,然后像Activity那样,在onCreate方法写逻辑即可
  • 性能优异,动画流畅;精心优化的动画,让你很难遇到卡顿场景
  • 能在应用后台弹出(需要申请悬浮窗权限,一行代码即可)
  • 支持androidx
  • 完美支持RTL布局
  • 如果你想要时间选择器和城市选择器,可以使用XPopup扩展功能库XPopupExt: https://github.com/li-xiaojun/XPopupExt
  • 设计思路: 综合常见的弹窗场景,我将其分为几类:


  • Center类型,就是在中间弹出的弹窗,比如确认和取消弹窗,Loading弹窗
  • Bottom类型,就是从页面底部弹出,比如从底部弹出的分享窗体,知乎的从底部弹出的评论列表,内部已经处理好手势拖拽和嵌套滚动
  • Attach类型,就是弹窗的位置需要依附于某个View或者某个触摸点,就像系统的PopupMenu效果一样,但PopupMenu的自定义性很差,淘宝的商品列表筛选的下拉弹窗,微信的朋友圈点赞弹窗都是这种。
  • Drawer类型,就是从窗体的坐边或者右边弹出,并支持手势拖拽;好处是与界面解耦,可以在任何界面实现DrawerLayout效果
  • ImageViewer大图浏览类型,就像掘金那样的图片浏览弹窗,带有良好的拖拽交互体验,内部嵌入了改良的PhotoView
  • FullScreen类型,全屏弹窗,看起来和Activity一样,可以设置任意的动画器;适合用来实现登录,选择性的界面效果。
  • Position自由定位弹窗,弹窗是自由的,你可放在屏幕左上角,右下角,或者任意地方,结合强大的动画器,可以实现各种效果。

 


implementation 'com.lxj:xpopup:2.0.0'

底部弹窗,自定义布局


new XPopup.Builder(this)
.asCustom(new RefundPopup(this, new RefundPopup.OnClickListener() {
@Override
public void clickConfirm() {
new XPopup.Builder(GoodsOrderDetailActivity.this)
.asCustom(new RefundReasonPopup(GoodsOrderDetailActivity.this, new RefundReasonPopup.OnClickListener() {
@Override
public void clickConfirm(String tag,String msg) {
getPresenter().applyRefund(goodsOrderId,tag,msg);
}
})).show();
}
})).show();

 



public class RefundPopup extends BottomPopupView {

private Context context;
private OnClickListener mOnClickListener;

public RefundPopup(@NonNull Context context) {
super(context);
this.context = context;
}

public RefundPopup(@NonNull Context context, OnClickListener onClickListener) {
super(context);
this.context = context;
mOnClickListener = onClickListener;
}

@Override
protected int getImplLayoutId() {
return R.layout.popup_refund;
}

protected int getPopupWidth() {
return AutoUtils.getPercentWidthSize(750);
}

@Override
protected void onCreate() {
super.onCreate();
ImageView ivBack = findViewById(R.id.ivBack);
TextView tvConfirm = findViewById(R.id.tvConfirm);
TextView tvCancel = findViewById(R.id.tvCancel);
ivBack.setOnClickListener(view -> {
dismiss();
});
tvCancel.setOnClickListener(view -> dismiss());
tvConfirm.setOnClickListener(view -> {
mOnClickListener.clickConfirm();
dismiss();
});
}

public interface OnClickListener {
void clickConfirm();
}

}

资源下载:xpopup-master.zip


0 个评论

要回复文章请先登录注册