【发布时间】:2013-03-04 07:54:43
【问题描述】:
我有一个 ImageButton 并且我已经为它制作了一个选择器,所以当我按下 imagebutton 时,会显示另一个图像。但是当按下图像按钮时,似乎必须等待 1 秒才能更改图像。这对用户体验来说并不是很好。..
有没有可能解决这个问题?我已经查找了一些答案,但我现在不知道在哪里进行更改。
这是我的代码
选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/main_pressed" />
<item
android:state_enabled="true"
android:drawable="@drawable/main" />
</selector>
布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/bg" >
<ImageButton
android:id="@+id/mainMosque"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:contentDescription="@string/mainMosque"
android:src="@drawable/main_btn_mosque" />
</RelativeLayout>
【问题讨论】:
-
您在真实设备上或仅在模拟器上看到此行为?
-
你的形象是不是很大?也许按下按钮需要 GC 运行。一些 logcat 输出会很有用。此外,您可以使用分析器运行您的应用程序并检查自己,是什么花费了这么多时间。
-
它在一个真实的设备上,三星 Galaxy S3。 xhdpi 中的图像是 512x512,ldpi 中的图像是 192x192。如何使用 logcat 输出这些数据以及什么是分析器?
标签: android android-layout imagebutton android-image android-selector