MyView 扩展了 View,并在 onDraw() 中绘制了一个圆圈。但是,如果我将边距设置为其父布局,它通常会被剪裁:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="10dp"
... >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RAM" />
<my.ui.ClockView2
android:padding="5dp"
android:id="@+id/ram_cv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="1"
android:visibility="visible" />
我试图计算边距,但只得到了填充:
_availableWidth = getWidth() - getPaddingLeft() - getPaddingRight();
_availableHeight = getHeight() - getPaddingTop() - getPaddingBottom();
有没有办法避免这种情况,提前谢谢!