ActivityにViewを配置する
Javaのみで
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... // Viewのインスタンスを生成 (アプリのコンテキストを参照して ) HogeView myView = new HogeView( getApplication() ); // 画面に配置 setContentView(myView);
レイアウトを使用
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... // レイアウトにしたがって画面に配置 setContentView(R.layout.activity_main); // 必要ならレイアウトからインスタンスを取得 HogeView myView = (HogeView)findViewById(R.id.hogeView1);
Viewの背景
Javaで
myView.setBackgroundResource(R.drawable.bg);
レイアウトで
<net.lipoyang.hoge.HogeView android:id="@+id/hogeView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg" />