RoundViewOutlineProvider.java 795 B

123456789101112131415161718192021222324252627282930313233343536
  1. package com.example.zhpan.banner.view;
  2. import android.annotation.TargetApi;
  3. import android.graphics.Outline;
  4. import android.graphics.Rect;
  5. import android.os.Build;
  6. import android.view.View;
  7. import android.view.ViewOutlineProvider;
  8. /**
  9. * <pre>
  10. * Created by zhangpan on 2018/12/26.
  11. * Description:圆角效果
  12. * </pre>
  13. */
  14. @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  15. public class RoundViewOutlineProvider extends ViewOutlineProvider {
  16. /**
  17. * 圆角弧度
  18. */
  19. private final float mRadius;
  20. public RoundViewOutlineProvider(float radius) {
  21. this.mRadius = radius;
  22. }
  23. @Override
  24. public void getOutline(View view, Outline outline) {
  25. // 绘制区域
  26. Rect selfRect = new Rect(0, 0, view.getWidth(), view.getHeight());
  27. outline.setRoundRect(selfRect, mRadius);
  28. }
  29. }