2013-03-06 2 views
5

아이콘과 텍스트를 그룹화하기 위해 선형 레이아웃으로 그룹화하고 선형 레이아웃을위한 리스너를 구현했습니다.onclicklistener에서 LinearLayout으로 발행 할 때

<LinearLayout 
     android:id="@+id/ll0" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="fill_horizontal" 
     android:orientation="vertical" > 
     <ImageButton 
      android:id="@+id/imageButton0" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:src="@drawable/start" /> 
     <TextView 
      android:id="@+id/textView0" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Start" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
    </LinearLayout> 

나는 청취자, 다음과 같은 방법을 구현 한 - 내가 직면하고있어

l0 = (LinearLayout)findViewById(R.id.ll0); 
l0.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      //Some Code 
     } 
    }); 

문제는 내가 아이콘을 클릭하는 즉, 청취자가 응답하지 않는 것입니다. 청취자는 텍스트보기와 아이콘 사이의 공간을 클릭하면 작동했습니다. 특정 부분이 아니라 전체 부분을 클릭 가능하게하고 싶습니다.

답변

6

ImageButton은 클릭 가능한 뷰이며 클릭 이벤트를 수신하지 못하도록 클릭을 캡처하고 있다고 생각합니다. ImageButton을 정의하는 XML에 android:clickable="false"을 추가하십시오.

그러나 더 나은 대답은 복합 드로어 블을 사용하는 것입니다. How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView을 참조하십시오. 기본적으로 TextView을 정의하는 XML에 android:drawableTop="@drawable/start"을 추가하고 LinearLayoutImageButton을 삭제할 수 있습니다. 그런 다음 TextView의 클릭 만 처리하면됩니다.

+1

android : 클릭 가능이 도움이되지 않는 것처럼 보이지만 컴파운드 드로어 블이 잘 작동합니다. – daemon54

관련 문제