Android ImageButton按钮状态图像未显示

Android ImageButton按钮状态图像未显示,android,png,android-imagebutton,slidingpanelayout,Android,Png,Android Imagebutton,Slidingpanelayout,我在华莱士·杰克逊的《面向绝对初学者的Android应用》第三版中工作 目前在第9章末尾(第350页) 我更新了资源目录中的PNG文件、imagebutton状态文件和主活动布局。我得到了一些意想不到的行为,这并不奇怪,因为大多数书籍的代码示例都不是开箱即用的,但我对这一点有点困惑。图像按钮不显示在滑动窗格布局的左窗格中。我可以看到三个白色的小矩形,它们应该是正方形(好吧,圆形,但从技术上讲,这些图像仍然是透明的正方形)。也应该有一些星系的照片 Android studio没有给我任何错误,状态

我在华莱士·杰克逊的《面向绝对初学者的Android应用》第三版中工作

目前在第9章末尾(第350页)

我更新了资源目录中的PNG文件、imagebutton状态文件和主活动布局。我得到了一些意想不到的行为,这并不奇怪,因为大多数书籍的代码示例都不是开箱即用的,但我对这一点有点困惑。图像按钮不显示在滑动窗格布局的左窗格中。我可以看到三个白色的小矩形,它们应该是正方形(好吧,圆形,但从技术上讲,这些图像仍然是透明的正方形)。也应该有一些星系的照片

Android studio没有给我任何错误,状态文件甚至有显示相应按钮状态资源的缩略图

我正在使用AndroidStudio 1.1.0和JRE 1.7.071。 我正在用安卓5.1调试谷歌Nexus7

按钮状态文件(请注意,stackoverflow正在取消终止选择器标记)


布局文件

<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/spLayout"
android:background="@drawable/ninepatchframe">
<LinearLayout
    android:layout_width="110dp"
    android:layout_height="match_parent"
    android:layout_weight="0.25"
    android:orientation="vertical">
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyOne"
        android:src="@drawable/ibstates1"
        android:contentDescription="@string/galaxyone"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyTwo"
        android:src="@drawable/ibstates2"
        android:contentDescription="@string/galaxytwo"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyThree"
        android:src="@drawable/ibstates3"
        android:contentDescription="@string/galaxythree"/>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@drawable/galaxyinfoscreen">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#00000000"
        android:layout_margin="12dp">
        <TextView
            android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="48dp" android:textStyle="bold"/>
        <TextView
            android:text="@string/galaxy_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF" />
        <TextView
            android:text="@string/galaxy_solar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_habit"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_colony"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_pop"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_fleet"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_ships"
            android:textColor="#FFFFFF" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#00000000"
        android:layout_marginTop="33dp">
        <TextView
            android:text="@string/name_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:id="@+id/name"/>
        <TextView
            android:text="@string/solar_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:id="@+id/solar"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/habit_data"
            android:textColor="#FFFFFF"
            android:id="@+id/habit"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/colony_data"
            android:textColor="#FFFFFF"
            android:id="@+id/colony"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/pop_data"
            android:textColor="#FFFFFF"
            android:id="@+id/pop"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/fleet_data"
            android:textColor="#FFFFFF"
            android:id="@+id/fleet"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ships_data"
            android:textColor="#FFFFFF"
            android:id="@+id/ships"/>
    </LinearLayout>
</LinearLayout>

另一件奇怪的事。。。我不认为这有什么关系,但谁知道呢。书中的屏幕截图显示了整个滑动窗格面板周围的九个补丁面板,但在我的应用程序中,九个补丁完全被右侧面板覆盖(在那一侧根本看不到)


有什么想法吗?

答案已经被其他人发布了。不幸的是,对他来说,链接帖子的OP从未承认PSIXO的正确答案


对于那些不想读取整个线程的人,物理文件名必须以“.xml”结尾。关于Android编程的书指导读者创建一个名为“ibstates”的文件,但名称必须是“ibstates.xml”,否则Android Studio将在引用该文件作为资源时中断并退出。

您的图像是否在
res/drawable
下?按钮状态xml文件在res\drawable下;实际png位于特定于分辨率的目录中(即res\drawable mdpi)。
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/spLayout"
android:background="@drawable/ninepatchframe">
<LinearLayout
    android:layout_width="110dp"
    android:layout_height="match_parent"
    android:layout_weight="0.25"
    android:orientation="vertical">
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyOne"
        android:src="@drawable/ibstates1"
        android:contentDescription="@string/galaxyone"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyTwo"
        android:src="@drawable/ibstates2"
        android:contentDescription="@string/galaxytwo"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyThree"
        android:src="@drawable/ibstates3"
        android:contentDescription="@string/galaxythree"/>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@drawable/galaxyinfoscreen">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#00000000"
        android:layout_margin="12dp">
        <TextView
            android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="48dp" android:textStyle="bold"/>
        <TextView
            android:text="@string/galaxy_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF" />
        <TextView
            android:text="@string/galaxy_solar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_habit"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_colony"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_pop"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_fleet"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_ships"
            android:textColor="#FFFFFF" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#00000000"
        android:layout_marginTop="33dp">
        <TextView
            android:text="@string/name_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:id="@+id/name"/>
        <TextView
            android:text="@string/solar_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:id="@+id/solar"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/habit_data"
            android:textColor="#FFFFFF"
            android:id="@+id/habit"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/colony_data"
            android:textColor="#FFFFFF"
            android:id="@+id/colony"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/pop_data"
            android:textColor="#FFFFFF"
            android:id="@+id/pop"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/fleet_data"
            android:textColor="#FFFFFF"
            android:id="@+id/fleet"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ships_data"
            android:textColor="#FFFFFF"
            android:id="@+id/ships"/>
    </LinearLayout>
</LinearLayout>