-
-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get a round corner BlurView? #37
Comments
Create a rounded drawable, as usual, set it as a |
It works, Thanks for your help :) 👍 @Dimezis |
This crashes my app: |
@mauriciogior because it's API 21, and you are running it <21. Android Studio should give you a warning |
@Dimezis yeah, thanks. It is a known bug https://issuetracker.google.com/issues/63151548 |
@Dimezis so for API < 21, no round corners? |
For sure it's possible to have rounded corners, but you'll have to fork the lib and implement it manually. |
Here is a solution for anyone wondering how to do it (just wrap public class CornerView extends FrameLayout {
private Path path = new Path();
private float radius = 0;
public CornerView(Context context) {
super(context);
}
public CornerView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CornerView);
try {
radius = a.getDimension(R.styleable.CornerView_radius, 0);
} finally {
a.recycle();
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
RectF rect = new RectF();
path.reset();
rect.set(0, 0, w, h);
path.addRoundRect(rect, radius, radius, Path.Direction.CW);
path.close();
}
@Override
protected void dispatchDraw(Canvas canvas) {
int save = canvas.save();
canvas.clipPath(path);
super.dispatchDraw(canvas);
canvas.restoreToCount(save);
}
} |
I can't get this to work, can anyone see what I am doing wrong? I have a semi transparent drawable with rounded corners, which is used as the background to the BlurView (api is 28). Fragment's onCreateView
|
@danielwilson1702 post your drawable |
My blind guess you're using per-corner radius, which is not supported. <corners android:bottomLeftRadius="..."
android:bottomRightRadius="..."
android:topLeftRadius="..."
android:topRightRadius="..."/> And you should use just <corners android:radius="..." /> |
Brilliant thank you, I wouldn't have thought of that 💯 |
Hi Dimezis, Can you please tell me where I am getting wrong ` <eightbitlab.com.blurview.BlurView
Also I am Using in MainActivity.Class ` topBlurView = findViewById(R.id.topBlurView);
|
Can you please send the attr class also |
@Dimezis Is it possible to have only some of the corners rounded? For example, only top left and top right? P.S. Дякую за лібу! |
Overall it's possible if you subclass the BlurView and mask those corners manually. But it's not possible with the XML drawable and clipToOutline, because it doesn't support complex shapes. |
@Dimezis is there any example to achieve this? I am really weak with canvas and paint API. |
@nauhalf there's a solution in this thread already - |
No description provided.
The text was updated successfully, but these errors were encountered: