【Android开源库】自带半透明遮罩层动画的FrameLayout

AlphaMaskLayout

Platform

API

popupwindow或者dialog弹出的时候,指定某个布局有一个透明度的过渡效果

1.支持自定义开始结束透明度、动画时间

2.透明度动画可以中断继续或返回

→_→城市选择推荐使用CityPicker

Gif

【Android开源库】自带半透明遮罩层动画的FrameLayout_第1张图片
image

Install

Gradle:

compile 'com.zaaach:alphamasklayout:1.1'

or Maven:


  com.zaaach
  alphamasklayout
  1.1
  pom

or 下载library手动导入.

Usage

AlphaMaskLayout extends FrameLayout.

attrs for AlphaMaskLayout


        
        
        
        
        
        

Step1:

在XML中添加


    //your layout here
    //...
    //...

其中android:foreground="#000"就是遮罩层的颜色,不设置则使用默认值#1f1f1f.

//you can also do in java like this:
maskLayout.setAlphaFrom(0);
maskLayout.setAlphaTo(127);
maskLayout.setDuration(600);

Step2:

activity中调用

//显示
moreBtn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        View content = LayoutInflater.from(MainActivity.this).inflate(R.layout.popup, null);
        mPopupWindow = new PopupWindow(content, 300, 400);
        mPopupWindow.setFocusable(true);
        mPopupWindow.setOutsideTouchable(true);
        mPopupWindow.setBackgroundDrawable(new ColorDrawable());
        mPopupWindow.showAsDropDown(moreBtn);
        mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
              @Override
              public void onDismiss() {
                maskLayout.hideMask();
              }
        });
        maskLayout.showMask();
      }
});
//监听器
maskLayout.setOnAlphaFinishedListener(new AlphaMaskLayout.OnAlphaFinishedListener() {
            @Override
            public void onShowFinished() {
                Toast.makeText(MainActivity.this, "show finished", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onHideFinished() {
                Toast.makeText(MainActivity.this, "hide finished", Toast.LENGTH_SHORT).show();
            }
        });

Step3:

Done! hope it will be useful.

Github

github地址:AlphaMaskLayout 欢迎star~

你可能感兴趣的:(【Android开源库】自带半透明遮罩层动画的FrameLayout)