首页 > 解决方案 > ImageButton 会导致未解决的 R 吗?

问题描述

试图创建一个带有几个 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>

标签: androidimagebutton

解决方案


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

请试试

android:background="@null"

它可能会帮助你。


推荐阅读