2014-03-24 3 views
2

내 프로젝트에서 서랍 레이아웃을 사용합니다. 서랍을 Google+ Android App처럼 맞춤 설정하고 싶습니다. "기본"ListView를 통해 ImageView를 추가했습니다. 그게 잘된거야. 코드는 다음과 같습니다 맞춤 서랍 레이아웃 - 투명도 클릭

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<RelativeLayout 
    android:id="@+id/drawer_layout_relative" 
    android:layout_width="240dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="start" > 

    <ImageView 
     android:id="@+id/drawer_header_image" 
     android:layout_width="wrap_content" 
     android:layout_height="85dp" 
     android:src="@drawable/ic_logo_blue" /> 

    <ProgressBar 
     android:id="@+id/drawer_progress" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/drawer_header_image" 
     android:background="#ffffffff" /> 

    <ListView 
     android:id="@+id/drawer_listview" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_below="@id/drawer_progress" 
     android:background="#ffffffff" 
     android:choiceMode="singleChoice" /> 
</RelativeLayout> 

리스트 뷰-항목 중 하나 FrameLayout이에 조각로드를 클릭

. 그게 완벽하게 작동합니다. 하지만 한 가지 문제가 있습니다. ImageView도 "클릭 가능"합니다. 그래서 Drawer가 열리면 ImageView를 클릭 할 것입니다. 뒤에있는 ListView가 클릭됩니다 !! 나는 그것을 원하지 않는다. 그래서 저는 clickable로 시도했습니다 : ImageView에서 false. 여기에 약간의 데모를 들어 ...

를 작동하지 마십시오 비디오입니다 : http://www.vidup.de/v/Ao71r/

어떻게 내가 이미지 뷰를 클릭하지 만들 수 있습니다!

답변

5

클릭 수가 서랍을 지나가는 것을 계속 유지하려면 서랍의보기, 특히 서랍에있는 다른 모든보기의 상위보기에서 true로 설정해야합니다. 그것의 아이들이 그 (것)들을 소모하지 않는 경우에 모든 접촉 사건을 소모한다.

는 다음에 drawer_layout_relative에 대한 RelativeLayout의 코드를 변경

(참고 : 상대 레이아웃에 클릭 = "true"로을 : 나는 안드로이드 추가) : 기본적으로

<RelativeLayout 
    android:id="@+id/drawer_layout_relative" 
    android:layout_width="240dp" 
    android:clickable="true" 
    android:layout_height="wrap_content" 
    android:layout_gravity="start" > 

, 뷰하지 않는 경우 클릭을 처리하면 클릭이 그 뒤의보기로 이동합니다. ImageView, ProgressBarListView : ListView는 클릭 이벤트를 처리하므로 해당 이벤트를 사용합니다. 기본적으로 ProgressBar 및 ImageViews는 물건 만 표시하고 클릭 수를 처리하지 않으므로 시스템은 서랍 뒤에있는 목록으로 클릭을 전달합니다. 이 세 가지 견해는 모두 RelativeLayout 안에 있습니다. RelativeLayout을 클릭 가능으로 설정하면 ImageView 및 ProgressBar에서 처리하지 않는 클릭 이벤트를 수집하고 클릭 이벤트가 그 아래보기로 이동하게하지 않습니다.

android : clickable = "true"으로 설정하면보기 아래에있는 모든보기와의 상호 작용을 차단할 수 있습니다.

자세한 내용은 this question

+0

을 참조하십시오. 완벽하게 작동합니다. 그러나 "클릭 할 수 없음"을 원할 때보기를 클릭 할 수있게 만드는 작은 쿠로스 :) – StefMa

+1

전체 서랍을 클릭 할 수있게하면 서랍 아래의보기가 클릭을 볼 수 없게됩니다. 내가 더 많은 설명과 함께 내 대답을 업데이 트, 잘하면 그것이 일을 좀 더 명확하게 도와줍니다 :) – anthonycr