次のように、ImageButton と TextView を LinearLayout でラップしています。
<LinearLayout android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="20" android:gravity="center"
android:clickable="true" android:id="@+id/action_showhide">
<ImageButton android:id="@+id/test"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/ic_toggle_hide_states" android:background="@null"></ImageButton>
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/txtHide"
android:textColor="@drawable/orange" android:textStyle="bold"></TextView>
</LinearLayout>
ImageButton は、通常の状態、フォーカスされた状態、および押された状態のカスタム ドローアブルによって支えられています。ユーザーが LinearLayout の任意の場所をクリックして OnClick イベントを発生できるようにしたいと考えています。以下のコードは、OnClickListener のセットアップを示しています。
final LinearLayout actionHide = (LinearLayout) findViewById(R.id.action_showhide);
actionHide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(AppAdvocate.TAG, "Event caught");
}
});
コードは、ユーザーが TextView の任意の場所をクリックすると機能しますが、ユーザーが ImageButton をクリックすると、イベントは LinearLayout までバブルアップしません。ボタンの onClickListener を定義していません。ImageButton のドローアブルを変更したいので、clickable=false に設定したくありません。イベントを盛り上げる方法はありますか?