剪辑 GradientDrawable.setCornerRadii 不工作
Clip For GradientDrawable.setCornerRadii not working
我正在尝试创建具有自定义半径的视图,但在使用 GradientDrawable.setCornerRadii...
Line 时遇到问题如果我使用下面的代码,视图会剪辑其中的所有子视图
public void SetCornerRadius(View v,int Radius){
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadius((int)Px2Dp(Radius));
v.setBackground(shape);
v.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
v.setClipToOutline(true);
}
但是如果我对不同的角半径使用下面的代码,那么当子视图超出父视图时,剪裁无法按预期工作
public void SetDifferentCornerRadius(View v,int TopLeftRadius,int TopRightRadius,int BottomLeftRadius,int BottomRightRadius,String backgroundColor){
GradientDrawable shape = new GradientDrawable();
ViewGroup vg = (ViewGroup)v;
shape.setShape(GradientDrawable.RECTANGLE);
shape.setColor(Color.parseColor(backgroundColor));
shape.setCornerRadii(new float[] { (int)Px2Dp(TopLeftRadius),(int)Px2Dp(TopLeftRadius),(int)Px2Dp(TopRightRadius),(int)Px2Dp(TopRightRadius),(int)Px2Dp(BottomRightRadius),(int)Px2Dp(BottomRightRadius),(int)Px2Dp(BottomLeftRadius),(int)Px2Dp(BottomLeftRadius)});
v.setBackground(shape);
v.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
v.setClipToOutline(true);
}
我猜它不起作用,因为 setClipToOutline
仅适用于以下形状。
Currently, only Outlines that can be represented as a rectangle, circle, or round rect support clipping.
https://developer.android.com/reference/android/graphics/Outline#canClip()
我正在尝试创建具有自定义半径的视图,但在使用 GradientDrawable.setCornerRadii...
Line 时遇到问题如果我使用下面的代码,视图会剪辑其中的所有子视图
public void SetCornerRadius(View v,int Radius){
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setCornerRadius((int)Px2Dp(Radius));
v.setBackground(shape);
v.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
v.setClipToOutline(true);
}
但是如果我对不同的角半径使用下面的代码,那么当子视图超出父视图时,剪裁无法按预期工作
public void SetDifferentCornerRadius(View v,int TopLeftRadius,int TopRightRadius,int BottomLeftRadius,int BottomRightRadius,String backgroundColor){
GradientDrawable shape = new GradientDrawable();
ViewGroup vg = (ViewGroup)v;
shape.setShape(GradientDrawable.RECTANGLE);
shape.setColor(Color.parseColor(backgroundColor));
shape.setCornerRadii(new float[] { (int)Px2Dp(TopLeftRadius),(int)Px2Dp(TopLeftRadius),(int)Px2Dp(TopRightRadius),(int)Px2Dp(TopRightRadius),(int)Px2Dp(BottomRightRadius),(int)Px2Dp(BottomRightRadius),(int)Px2Dp(BottomLeftRadius),(int)Px2Dp(BottomLeftRadius)});
v.setBackground(shape);
v.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
v.setClipToOutline(true);
}
我猜它不起作用,因为 setClipToOutline
仅适用于以下形状。
Currently, only Outlines that can be represented as a rectangle, circle, or round rect support clipping.
https://developer.android.com/reference/android/graphics/Outline#canClip()