main.xml のソース
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <com.androidGui.CustomView android:id="@+id/custumView" android:layout_width="wrap_content" android:layout_height="fill_parent" /> </LinearLayout>
CustomView.java のソース
package com.androidGui;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
public class CustomView extends View {
public CustomView(Context context, AttributeSet attrs) {
super(context);
setFocusable(true);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 通常はグラフィックを描画するコードをここに記述する。
canvas.drawColor(Color.BLUE);
}
}
【注意】コンストラクタを追加するとき、
public CustomView(Context context) {
でない事に注意する。setFocusable(true);も必ず必要か?
AndroidGui.java のソース
package com.androidGui;
import android.app.Activity;
import android.os.Bundle;
public class AndroidGui extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
追記:2013/0313


0 件のコメント:
コメントを投稿