我一直在努力尋找StackOverflow或其他地方的解決方案,但我找不到任何直接發佈有關此特定問題的帖子,可能除了可能最接近的一個我再也找不到了。不過,如果這只是因爲我忽略了某些東西,或者我只是一個很大的小菜鳥,提前很抱歉。ViewFlipper的onTouch事件不會被觸發,而其子按鈕的onClick事件是
無論如何,我想將一個ViewFlipper(父母)和setOnClickListener的OnTouchListener設置爲一個按鈕(子),它填充父級佈局明智。我想先調用ViewFlipper的onTouch()事件。如果ViewFlipper的onTouch()返回false,則認爲Button的onClick()被觸發。但是,只調用Button的onClick()。爲什麼?有沒有明確的優先權?因爲Button有'match_parent'屬性,所以觸摸這個viewflipper與觸摸這個按鈕幾乎是一樣的,即使我這樣做了,它只是讓Button的onClick() )事件不發火....
以下是我的簡化活動;
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>