2016-06-12 5 views
0

我在水平LinearLayout中有兩個TextView,它包含在另一個可點擊的容器中 - android:clickable="true"。我不希望點擊通過LinearLayout的孩子,但他們正在通過其中一個孩子。點擊次數通過LinearLayout中的一個兄弟,但不通過其他

這兩個TextView孩子幾乎相同,除了他們的身份證,體重和重力屬性;然而,我試圖設置除了ID之外的所有東西都是平等的,但點擊仍然通過其中一個兄弟姐妹。

以編程方式,沒有發生一個不會發生在另一個。這是最奇怪的事情。

下面是LinearLayout代碼:

*的點擊都在流血通過@id/sibling_2

<LinearLayout 
      android:id="@+id/linear_layout_container" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/maring_left" 
      android:layout_marginRight="@dimen/maring_right" 
      android:layout_marginTop="@dimen/top_margin" 
      android:layout_weight="1" 
      android:background="@drawable/bg"> 

      <TextView 
       android:id="@+id/sibling_1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="30" 
       android:padding="@dimen/padding" 
       android:gravity="center_horizontal" 
       android:textSize="@dimen/text_size" 
       android:hint="Score"/> 

      <!--the text view that clicks are bleeding through--> 
      <TextView 
       android:id="@+id/sibling_2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="@dimen/padding" 
       android:gravity="center" 
       android:textSize="@dimen/text_size" 
       android:hint="100%"/> 

     </LinearLayout> 
+0

顯示,如果 – VenomVendor

+0

@VenomVendor不知道你看到的更新您的Java代碼,但我刪除它,因爲我長大的那個是不正確的點。如果你確實看到它,'interim_container'仍然註冊點擊,即使我不清空它的背景 –

+0

@VenomVendor,並且只要java代碼去除了,除了通過它們的id找到視圖,然後設置它們的文本 –

回答

0

我修改你的佈局。這也許可以爲你工作:

<LinearLayout 
      android:id="@+id/linear_layout_container" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/maring_left" 
      android:layout_marginRight="@dimen/maring_right" 
      android:layout_marginTop="@dimen/top_margin" 
      android:weightSum="2" 
      android:background="@drawable/bg"> 

      <TextView 
       android:id="@+id/sibling_1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="@dimen/padding" 
       android:gravity="center_horizontal" 
       android:textSize="@dimen/text_size" 
       android:hint="Score"/> 

      <TextView 
       android:id="@+id/sibling_2" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="@dimen/padding" 
       android:gravity="center" 
       android:textSize="@dimen/text_size" 
       android:hint="100%"/> 

     </LinearLayout> 
+0

完全嘗試了這些更改,但沒有成功 –

+0

textview沒有得到點擊我是對不對? – savepopulation

+0

兩個'TextView'都可能被點擊。問題是當單擊「@ id/sibling_2」時,註冊了「@ id/super_container」的點擊事件 - 檢查更新。當'sibling_1'被點擊時,什麼都不會發生,這就是兩個'TextView'發生的事情 –