私はStackOverflowなどでソリューションを見つけるのに苦労していますが、この特定の問題について直接の投稿は見つかりませんでした私がもはや見つけることができない最も近いもの。しかし、もし私が何かを見落としただけであれば、私はあまりにも大きな騒ぎです。ViewFlipperのonTouchイベントは、子ボタンのonClickイベントが発生していないときに発生します
とにかく、OnTouchListenerをViewFlipper(親)に設定し、setOnClickListenerを親(親)レイアウトを塗りつぶしたボタン(子)に設定しようとしています。私はViewFlipperのonTouch()イベントを最初に呼びたいと思っていました。 ViewFlipperのonTouch()がfalseを返した場合、ButtonのonClick()が発生したと考えられます。ただし、ボタンのonClick()だけが呼び出されました。どうして?定義済みの優先順位はありますか?
また、Buttonに 'match_parent'属性が設定されているため、onTouchListenerを設定することができます。このビューフッタをタッチすることは、このボタンをタッチすることと事実上同じです(ボタンのonClick )イベントunfired ....
以下は私の簡単なアクティビティです。
public class TestActivity extends Activity implements OnTouchListener, View.OnClickListener {
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewFlipper vf = (ViewFlipper) findViewById(R.id.viewFlipper1);
Button btn = (Button) this.findViewById(R.id.btnTest1);
vf.setOnTouchListener(this);
btn.setOnClickListener(this);
}
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">
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:id="@+id/button"
layout="@layout/test" />
</ViewFlipper>
</LinearLayout>
のtest.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/testLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical" >
<Button
android:id="@+id/btnTest1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button" />
</LinearLayout>