我有一个显示位图的 ImageView。在它的 onDraw 方法中,我使用 clipRect 从底部切掉一些像素。这工作正常,但 ImageView 的高度没有调整到修改后的画布,因此留下了不需要的空间。我怎样才能摆脱它?
我一直在尝试相应地降低父母的身高并将其 clipChildren 设置为 false,但这会导致一些问题。
@Override
protected void onDraw( Canvas canvas )
{
Path clipPath = new Path();
clipPath.addRoundRect(
new RectF( 0, 0, width, height - (int) ( watermarkHeight * scale ) ),
cornerRadius,
cornerRadius,
Path.Direction.CW );
clipPath.addRect( 0, 0, width, cornerRadius, Path.Direction.CW );
canvas.clipPath( clipPath );
super.onDraw( canvas );
}