2012-06-12 3 views
0

여기에 새로운 질문이 있습니다 :Android 버튼 - 프레스 상태에서 이미지 투명도 유지

부분적으로 투명한 PNG 배경이있는 버튼이 있습니다. 여러 언론에 걸쳐 버튼의 투명성을 유지하려고합니다. 문제는 배경 이미지에 그라디언트를 적용하면 (버튼을 누르는 것을 나타 내기 위해) 그라디언트가 이미지 자체가 아니라 이미지가 차지하는 전체 '블록 공간'을 어둡게 만듭니다.

이미지의 투명 부분을 투명하게 유지하려면 어떻게해야합니까? 미리 감사드립니다 ...

selector_button_singleplayer.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/button_singleplayer" /> 
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/gradient_button_singleplayer" /> 
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/gradient_button_singleplayer" /> 
<item android:drawable="@drawable/button_singleplayer" /> 

gradient_button_singleplayer.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item> 
    <bitmap android:src="@drawable/button_singleplayer"/> 
</item> 
<item> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
     <gradient android:angle="90" android:startColor="#880f0f10" android:centerColor="#880d0d0f" android:endColor="#885d5d5e"/> 
    </shape> 
</item> 
</layer-list> 

내 버튼 :

<Button android:id="@+id/main_menu_choose_single_player" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginRight="25dip" 
android:background="@drawable/selector_button_singleplayer" 
/> 

답변

0

이동하여 ImageButton

설정 안드로이드 : button_singleplayer

으로 SRC와 gradient_button_singleplayer.xml는

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
     <gradient android:angle="90" android:startColor="#880f0f10" android:centerColor="#880d0d0f" android:endColor="#885d5d5e"/> 
    </shape> 

될 것입니다 귀하의 selector_button_singleplayer.xml이 될 것입니다

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
<item android:state_focused="true" android:state_pressed="false" android:drawable="@android:color/transparent" /> 
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/gradient_button_singleplayer" /> 
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/gradient_button_singleplayer" /> 
<item android:drawable="@android:color/transparent" /> 

이고 imageButton은

<ImageButton android:id="@+id/main_menu_choose_single_player" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginRight="25dip" 
android:background="@drawable/selector_button_singleplayer" 
android:src="@drawable/button_singleplayer" 
/> 
+0

입니다. 감사합니다. 나는 그 대답이 바른 길에 있다고 생각한다. 그러나 이제 그라디언트는 배경에만 적용되며 이미지 자체는 완전히 변경되지 않습니다. 전체 블록이 어두워지기 전에는 이제 이미지의 투명도 만 영향을받습니다. 하지만 어쩌면 거기에서 해결할 수 있습니다. 귀하의 답변에 감사드립니다. – rustyWhitefeather