今回は画像をボタンにしたいと思います。
ImageButtonはクリックイベントを取得したい時などに利用をします。
AndroidManifest.xmlは
特に変更しません。
レイアウトは
<ImageButton android:id="@+id/imageButton1" android:scaleType="fitCenter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" />
メインのクラスでクリックのイベントを取得できます。
((ImageButton)findViewById(R.id.imageButton1)).setOnClickListener(new OnClickListener() { public void onClick(View v) { //CLICK!! } });
下記のようになるはずです!
背景にはボタンがあります。ボタンの背景を消したい時には、backgroundに@nullを設定します。
<ImageButton android:id="@+id/imageButton1" android:scaleType="fitCenter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" android:background="@null" />