我创建了我的自定义可绘制对象。为了绘制它,我使用了边界。但是,当用户使用:
android:layout_width="match_parent"
android:layout_height="wrap_content"
我得到 bounds.height() == 1。然后,我想用作 height = 0.8 * bounds.width。
我试过了,因为当用户使用 WRAP_CONTENT 时,我得到 bounds.height() = 1。所以我将可绘制高度设置为 0.8*width()。但我没有得到合适的尺寸。我只是觉得高度是 1。我读到你需要调用 invalidate(),但是我该如何调用它,因为如果我在draw()中调用 invalidate(),那么该方法将被无限调用。