2012-12-05 5 views
2

So. Google+ 앱에서 소식을 클릭하면 전체보기가 파란색으로 변하는 것을 알 수 있습니다. 그뿐만 아니라 ImageView를 사용하고 싶습니다.보기에서 투명한 색상 강조 표시를 클릭했을 때

실제 이미지를 배경으로 설정하고 선택자를 주 리소스로 설정하는 다음 코드 단편을 가지고 있습니다. 이 좋은 보이지만, 배경 이미지에 대한 scaleType을 존중하지 않습니다

<item android:state_pressed="true"> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
     <solid android:color="#44521400" /> 
    </shape></item> 

어떻게 만들 수 있습니다 : 그런데

 <ImageView 
      android:id="@+id/painting_image" 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:background="@drawable/img" 
      android:src="@drawable/selector" 
      android:scaleType="centerCrop" /> 

, @drawable/selectorstate_pressed에 대한 tranparent 색상을 보여줍니다 단지 선택이다 이 작업은 scaleType을 존중하면서?

답변

8

ImageViewFrameLayout A의 랩, 그리고 클릭 할 수하는 FrameLayout을 정의 :이처럼 클릭 동작을 구현됩니다 오버레이 볼 수있는 두 번째 옵션을 사용하는 것이 좋습니다. onClick 이벤트를 FrameLayout에 할당하고 ImageView으로 할당하지 않도록주의하십시오. 그렇지 않으면 효과가 중단됩니다! 또한 foregroundbackground이 아니라 선택기로 설정되었습니다.

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:foreground="@drawable/imagebutton_selector" > 

     <ImageView 
      android:id="@+id/painting_image" 
      android:layout_width="match_parent" 
      android:layout_height="250dp" 
      android:scaleType="centerCrop" /> 

    </FrameLayout> 
+0

의미가 있습니다 ... 더 나아졌습니다! –

+0

예 : imagebutton_selector.xml : drawable = "@ color/bg_window"/> ' – moondroid

1

ScaleType은 배경이 아닌 src 드로어 블에만 적용됩니다.

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/painting_image" 
      android:layout_width="match_parent" 
      android:layout_height="250dp" 
      android:scaleType="centerCrop" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="250dp" 
      android:background="@drawable/imagebutton_selector" 
      android:onClick="onImageClick" /> 
    </FrameLayout> 
+1

안녕하세요, 귀하의 제안에 감사드립니다. 그러나 나는 이미 내 자신의 질문에 대답했다. onClick 이벤트를 'FrameLayout' 래핑하는 것을 잊었습니다. 그것은 여전히'ImageView'를 위해 정의되었습니다. – Maarten

관련 문제