Imageview.setxxx can set
Setbackgroundresource background,
Layout Setlayoutparams
and Setscaletype,
The source picture cannot be changed. Don't worry. If the picture is rotated, only another bitmap is generated
Solutions
First, create an XML file under the Res/drawable folder, named Logoutimage.xml, in which the image is actually clicked before and when clicked, the code is as follows:
code is as follows |
copy code |
<?xml Version= "1.0" encoding= "Utf-8" <selector xmlns:android= "Http://schemas.android.com/apk/res/android" <!--default picture--> <item android:state_pressed= "false" & nbsp android:drawable= "@drawable/logout2"/> <!--click picture--> <item android:state_pressed= "true" android:drawable= "@drawable/logout1"/> </selector> |
The file is then referenced in the src attribute of ImageView, and the code is as follows:
The code is as follows |
Copy Code |
<imagebutton android:src= "@drawable/logoutimage" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" /> |
More information
The code is as follows |
Copy Code |
<!--default picture--> <item android:drawable= "@drawable/img1"/> <!-- Picture--> with no focus <item android:state_window_focused= "false" android:drawable= "@drawable/img2"/>&NBSP;&NBSP;&NBSP;&NBSP; <!--picture--> when getting focus <item android:state_focused= "true" android:drawable= "@drawable/img3"/>
< pictures When selected!----> <item android:state_selected= "true" android:drawable= "@drawable/img4"/>
<!--picture--> when clicked in touch mode <item android:state_focused= "false" Android:state_pressed= "true" android:drawable= "@drawable/img5"/>
< picture--> When you get focus and click in non-touch mode!-- <item android:state_focused= "true" Android:state_pressed= "true" android:drawable= "@drawable/img6"/> |
Method of these, we can look at the following effect chart