Android有可以定制上下左右角为圆角的View控件吗
是的,Android提供了可以定制上下左右角为圆角的View控件。可以通过设置View的背景为一个带圆角的ShapeDrawable或者使用自定义的RoundRectShape来实现。以下是一个示例代码:
// 创建一个带圆角的ShapeDrawable
ShapeDrawable shapeDrawable = new ShapeDrawable();
float[] radii = {20, 20, 20, 20, 0, 0, 0, 0}; // 设置上下左右的圆角半径
shapeDrawable.setShape(new RoundRectShape(radii, null, null));
shapeDrawable.getPaint().setColor(Color.RED);
// 将ShapeDrawable设置为View的背景
View view = findViewById(R.id.your_view);
view.setBackground(shapeDrawable);
通过上述代码,你可以将your_view的上下左右角设置为圆角。你可以根据需要调整圆角的半径和颜色
原文地址: https://www.cveoy.top/t/topic/ibuw 著作权归作者所有。请勿转载和采集!