1.x版本 | 2.x版本
抽象出一个方便自定义的Basepopup类,更加方便的创建出一个popup以及动画效果
| Release | Candy | License | Api | Author |
|---|---|---|---|---|
| |
|
请务必查看更新日志和例子预览,里面会详细解释每个版本增加或修复的功能
请注意引用版本的问题,Release版本是稳定版,可商用。
Candy不稳定(且更新很频繁),但包含着新功能或者新的优化,不建议商用。
关于V2版本更新(现已在Candy发布2.0.0alpha-1)
| Release | Candy |
|---|---|
| |
|
添加依赖(请把{latestVersion}替换成上面的Jcenter标签所示版本
【candy版本不一定稳定,包含有新功能或者新的修复,完善后将会发布其release版】
dependencies {
compile 'com.github.razerdp:BasePopup:{latestVersion}'
//candy版本,不稳定,但会带有新功能
//compile 'com.github.razerdp:BasePopup_Candy:{latestVersion}'
}
ps:从1.9.0-alpha开始支持背景模糊(只需要一个方法:setBlurBackgroundEnable())
RenderScript最低支持api 17(更低的情况将会使用fastblur),您需要在gradle配置一下代码
defaultConfig {
renderscriptTargetApi 25
renderscriptSupportModeEnabled true
}
像您平时定制activity布局文件一样定制您的popup布局(请注意,展示动画的那个view必须是popupview的子view)
etc.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8f000000">
<RelativeLayout
android:id="@+id/popup_anima"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog"
android:layout_centerInParent="true"
android:layout_margin="25dp">
<... many views>
</RelativeLayout>
</RelativeLayout>

新建一个类继承BasePopupWindow
实现必要的几个方法:
initShowAnimation():初始化一个进入动画,该动画将会用到initAnimaView()返回的view
onCreatePopupView():初始化您的popupwindow界面,建议直接使用createPopupById(),不能返回空值
getClickToDismissView():如果有需要的话,可以使用这个方法返回一个点击dismiss popupwindow的view(也许是遮罩层也许是某个view,这个随您喜欢)
例如
public class DialogPopup extends BasePopupWindow implements View.OnClickListener{
private TextView ok;
private TextView cancel;
public DialogPopup(Activity context) {
super(context);
ok= (TextView) findViewById(R.id.ok);
cancel= (TextView) findViewById(R.id.cancel);
setViewClickListener(this,ok,cancel);
}
@Override
protected Animation initShowAnimation() {
AnimationSet set=new AnimationSet(false);
Animation shakeAnima=new RotateAnimation(0,15,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
shakeAnima.setInterpolator(new CycleInterpolator(5));
shakeAnima.setDuration(400);
set.addAnimation(getDefaultAlphaAnimation());
set.addAnimation(shakeAnima);
return set;
}
@Override
protected View getClickToDismissView() {
return getPopupWindowView();
}
@Override
public View onCreatePopupView() {
return createPopupById(R.layout.popup_dialog);
}
@Override
public View initAnimaView() {
return findViewById(R.id.popup_anima);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.ok:
Toast.makeText(getContext(),"click the ok button",Toast.LENGTH_SHORT).show();
break;
case R.id.cancel:
Toast.makeText(getContext(),"click the cancel button",Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
}
把您刚才实现的popup给new出来并调用show方法
例如
DialogPopup popup = new DialogPopup(context);
popup.showPopupWindow();
请看wiki(陆续完善中)
Link👉WIKI
因为目前还有朋友圈项目,建立了一个交流群,出于懒得管理那么多,所以如果有想法或者优化建议或者其他问题,欢迎加入“朋友圈交流群”

| 微信 | 支付宝 |
|---|---|
![]() |
![]() |
2.0.0版本相关请查看分支:razerdp.basepopup v2
1.9.4(release)
发布1.9.4
1.9.4-alpha2(candy)
修复误打包测试代码的alpha1
1.9.4-alpha(candy)
showOnTop/showOnDown更名->onAnchorTop/onAnchorBottom,避免误导。
1.9.3(release)
修复了在popup外滑动时ViewGroup.LayoutParams的cast异常
1.9.2(release)
HackDecorView针对PopupWindow高度问题setBlurBackgroundEnable()模糊设置回调,允许自定义模糊操作修改为默认子线程模糊背景,同时增加blurImageView的模糊等待操作
1.9.1(release)
BasePopupWindow.debugLog(true)getTranslateAnimation() -> getTranslateVerticalAnimation()defaultConfig下添加两句:| 对应popup | 预览 |
|---|---|
| BlurSlideFromBottomPopup.java | ![]() |
| CommentPopup.java | ![]() |
| ScalePopup.java | ![]() |
| SlideFromBottomPopup.java | ![]() |
| InputPopup.java | ![]() |
| ListPopup.java | ![]() |
| MenuPopup.java | ![]() |
(很旧的文章了,考虑迟点重新编写)
http://www.jianshu.com/p/069f57e14a9c
Apache-2.0
$ claude mcp add BasePopup \
-- python -m otcore.mcp_server <graph>