0
高さと幅が同じである必要があるカスタムビューで作業しています。ビューのサイズを指定されたスペースに調整します。
私は、次の方法でそれを描く:
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(getWidth()/2, getHeight()/2, getWidth()/2, mPaint);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
widthMeasureSpec = heightMeasureSpec;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
私は画面上にあるビューを追加した場合、幅/高さはokです。ただし、これらのビューの2つを隣り合わせに追加すると、ビューのサイズを調整する必要があります(各ビュー:画面の半分の幅)。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<at.guger.widget.Light
android:id="@+id/lights_light1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="5dp" />
<at.guger.widget.Light
android:id="@+id/lights_light2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="5dp" />
</LinearLayout>
どうすればいいですか?