我有幾個seekbars作爲兒童的一個LinearLayout
,在SeekBars
我使用android:clickable=false
和上的LinearLayout我有android:clickable=true
和所定義的但是任何按下相應setOnClickListenner
SeekBars
不會觸發LinearLayout
點擊,我已經閱讀了某處,它應該通過將SeekBars
替換爲Buttons
並將clickable
屬性設置爲false
並將其點擊冒泡到父級來進行測試。 我的問題是爲什麼行爲不相似?的ViewGroup(的LinearLayout)和兒童onClick事件不傳遞到的ViewGroup
編輯:添加代碼示例
佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:longClickable="false"
android:focusable="false"
/>
<Button
android:layout_marginTop="10dp"
android:clickable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click me!"/>
</LinearLayout>
活動:
public class MyActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
ViewGroup container = (ViewGroup) findViewById(R.id.container);
container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MyActivity.this, "Container was clicked", Toast.LENGTH_SHORT).show();
}
});
}
}
嗯,你在代碼中缺少這個:「並且在LinearLayout上我有'android:clickable = true'」 – Darrell 2014-08-28 13:47:30
10是的,我發佈的是一個使用setOnClickListener的例子,它的不相關行爲是相同的,甚至與在單擊「LinearLayout」時沒有'android:clickable = true',在單擊SeekBar時調用監聽器,而不是在調用該事件的Button上執行。 – forcewill 2014-08-28 13:51:46
沒關係,所以當你點擊按鈕時它工作嗎?當你點擊搜索欄時它不起作用?正確? – Darrell 2014-08-28 13:53:36