【问题标题】:Can ImageButton cause an unresolved R?ImageButton 会导致未解决的 R 吗?
【发布时间】:2018-12-27 15:05:56
【问题描述】:

尝试创建一个带有几个 ImageButtons 的应用程序来播放声音。由于我添加到drawable文件夹的图像很大,认为它们会造成麻烦;因此使用启动器图像进行了测试,但出现了同样的错误。受够了这个烦人的麻烦..请提出一条出路..

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="28dp"
        android:layout_marginLeft="28dp"
        android:layout_marginTop="26dp"
        android:background="null"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageButton1"
        android:layout_centerHorizontal="true"
        android:background="null"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        app:srcCompat="@mipmap/ic_launcher" />


</RelativeLayout>

【问题讨论】:

  • 请发布您面临的错误

标签: android imagebutton


【解决方案1】:

我认为您的背景属性存在问题。您不能在背景属性中提供“null”值。

请尝试

android:background="@null"

也许对你有帮助。

【讨论】:

  • 我添加了背景属性,但错误没有散去。图片的大小会引发这样的错误吗?
  • @kshkz:如果可能,请分享您的代码。深入研究它以快速修复它会很有帮助。
  • 是的,没关系,但是您上面的 xml 使用 android:background="@null" 可以正常工作。而且您仍然遇到相同的错误。因此,如果可能,请分享您的活动和 mipmap 资源。找到解决方案会很有帮助。
  • @Ajay Mehta:衷心感谢您的好意。我正在尝试在此处粘贴 activity_main.xml,但此处不接受如此长的代码。这是一个令人烦恼的问题,但突然问题消失了,虽然我曾经考虑过重新安装Android Studio。如果再发生什么,我会再问。再次感谢您的好意。
  • @kshkz:如果您的问题已解决,请将此答案标记为已接受。
猜你喜欢
  • 2013-12-02
  • 2011-12-17
  • 1970-01-01
  • 2022-01-17
  • 2019-11-18
  • 2014-08-11
  • 2016-09-04
  • 1970-01-01
相关资源
最近更新 更多