Java 你知道有时候按下按钮或图片时,

Java 你知道有时候按下按钮或图片时,,java,android,android-studio,android-imagebutton,Java,Android,Android Studio,Android Imagebutton,你知道,有时候当按下按钮或图片时,图像会变小,然后当你松开它时,图像会恢复正常。在android studio中,如果使用图像按钮,您可以在按钮上设置一个onclicklistener或onlongPresslistener,该如何操作,按下按钮时,您可以缩小用于显示图像的imageview,松开按钮时,您可以显示原始图像。按钮上可以有onclicklistener或onlongPresslistener,按下按钮时,您可以缩小用于显示图像的imageview,松开按钮后,您可以显示原始图像。像

你知道,有时候当按下按钮或图片时,图像会变小,然后当你松开它时,图像会恢复正常。在android studio中,如果使用图像按钮,您可以在按钮上设置一个
onclicklistener
onlongPresslistener
,该如何操作,按下按钮时,您可以缩小用于显示图像的
imageview
,松开按钮时,您可以显示原始图像。

按钮上可以有
onclicklistener
onlongPresslistener
,按下按钮时,您可以缩小用于显示图像的
imageview
,松开按钮后,您可以显示原始图像。

像这样在drawable中创建一个xml文件并设置为背景

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/YourHoverImage" android:state_pressed="true"/>
    <item android:drawable="@drawable/NormalImage" android:state_pressed="false"/>
    <item android:drawable="@drawable/YourHoverImage" android:state_focused="true"/>
    <!-- default -->

</selector>


您可以这样做。

像这样在drawable中创建一个xml文件,并设置为背景

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/YourHoverImage" android:state_pressed="true"/>
    <item android:drawable="@drawable/NormalImage" android:state_pressed="false"/>
    <item android:drawable="@drawable/YourHoverImage" android:state_focused="true"/>
    <!-- default -->

</selector>

你可以这样做