나는 클래스에서 연장되는 GraphicsView
클래스를 가지고 있는데,이 GraphicsView
클래스를 내 프로젝트의 기본 레이아웃에 추가하려고합니다. 어떻게해야합니까?레이아웃에 맞춤보기를 추가하는 방법은 무엇입니까?
static public class GraphicsView extends View {
public GraphicsView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
// Drawing commands go here
Path rect = new Path();
rect.addRect(100, 100, 250, 50, Direction.CW);
Paint cPaint = new Paint();
cPaint.setColor(Color.LTGRAY);
canvas.drawPath(rect, cPaint);
}
}
내 main.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linnnnlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TextView
android:id="@+id/Customfont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<View
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
View.addView (yourView); – mihail
나는 이것을 어디에 넣어야 했습니까? – AnasBakez