每当我点击imageview时我都会收到此错误,当我在不同的屏幕尺寸上切换到测试我的应用时会发生这种情况,这是我的xml
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ahmed.electionadmin, PID: 30789
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ahmed.electionadmin/com.example.ahmed.electionadmin.Search}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
这是错误
{{1}}
我已经尝试了很多解决方案,要求我用srccompat替换src等等,但仍然有效,蚂蚁帮助将不胜感激
答案 0 :(得分:1)
替换它:
app:srcCompat="@drawable/search"
使用:
android:src="@drawable/search"
请注意
src
与srcCompat
,app
与android
。
让我知道它是否有效。
说明:您没有使用支持库ImageView
,而是常规支持库。 app
命名空间通常用于support library,与srcCompat
相同。所以你需要改变那些 2件事,而不仅仅是一件事。这就是为什么仅用srcCompat
改变src
没有产生结果。
答案 1 :(得分:1)
要使用srcCompat
,您需要将vectorDrawables.useSupportLibrary = true
添加到 build.gradle 文件中:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
或者您可以使用src
代替srcCompat
来解决错误。
android:src="@drawable/search"
答案 2 :(得分:1)
我通过在draawable no 24
中上传我的图像来修复它答案 3 :(得分:0)
你正在做的是将图像拟合到不同的分辨率,你应该有像hdpi xhdpi这样的不同分辨率的图像,你可以使用矢量可绘制的图像