/**
* 给view裁剪圆角半径
* @param view 要裁剪的view
* @param radius 圆角半径
*/
public static void clipViewRoundRect(View view, int radius) {
view.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius);
}
});
view.setClipToOutline(true);
}
/**
* 给view裁剪左边圆角半径
* @param view 要裁剪的view
* @param radius 圆角半径
*/
public static void clipViewLeftRoundRect(View view, int radius) {
view.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(0, 0, view.getWidth() + radius, view.getHeight(), radius);
}
});
view.setClipToOutline(true);
}
/**
* 给view裁剪右边圆角半径
* @param view 要裁剪的view
* @param radius 圆角半径
*/
public static void clipViewRightRoundRect(View view, int radius) {
view.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(-radius, -radius, view.getWidth() + radius, view.getHeight(), radius);
}
});
view.setClipToOutline(true);
}
上下同理,只要把rect定大一点,裁掉的部分看不到,那一条边就是直角了。