Android 为什么我的形象不';我测试的设备上没有显示?

Android 为什么我的形象不';我测试的设备上没有显示?,android,android-layout,Android,Android Layout,我使用的是一个像按钮一样的图像视图,但当我试图在drawable文件夹中创建一个XMLFIE来更改按钮按下时的图像时,其中一个图像没有显示出来 xml布局文件: <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> //the button below don't appear <ImageView

我使用的是一个像按钮一样的图像视图,但当我试图在drawable文件夹中创建一个XMLFIE来更改按钮按下时的图像时,其中一个图像没有显示出来

xml布局文件:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    //the button below don't appear
    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" app:srcCompat="@drawable/boutton_animation"
            android:id="@+id/play_button"

            android:layout_marginStart="61dp"
            android:layout_alignStart="@+id/play_bg"
            android:layout_alignTop="@+id/play_bg"
            android:layout_marginTop="320dp" android:layout_marginEnd="542dp" android:layout_alignEnd="@+id/play_bg"
            android:scaleType="fitXY" android:layout_marginBottom="33dp" android:layout_alignBottom="@+id/play_bg"
            android:visibility="visible"/>

</RelativeLayout>

//下面的按钮不会出现
按钮图像的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/boutton_animation_2" /> <!-- pressed -->
    <item android:drawable="@drawable/boutton_animation_1" /> <!-- default -->
</selector>


我没有收到错误消息,我唯一希望的是设备上出现的按钮

您没有看到您的图像,因为您在视图上使用的是固定大小的按钮

不同的手机有不同的屏幕大小,在您的布局中,您在视图上使用的是固定大小(例如,固定大小为
android:layout_margintart=“61dp”
),其结果是,在一个屏幕(您的android studio预览屏幕)上看起来不错的内容在另一个屏幕(您的实际手机)上看起来不太好

如果您希望在每台设备上以相同的方式查看图像,请如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layoutDirection="ltr"
  android:orientation="vertical">

<ImageView
    android:id="@+id/play_button"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHeight_percent=".5"
    app:layout_constraintWidth_percent=".5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:scaleType="fitXY"
    app:srcCompat="@drawable/rose" />


</android.support.constraint.ConstraintLayout>

您没有看到图像,因为您在视图上使用的是固定大小

不同的手机有不同的屏幕大小,在您的布局中,您在视图上使用的是固定大小(例如,固定大小为
android:layout_margintart=“61dp”
),其结果是,在一个屏幕(您的android studio预览屏幕)上看起来不错的内容在另一个屏幕(您的实际手机)上看起来不太好

如果您希望在每台设备上以相同的方式查看图像,请如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layoutDirection="ltr"
  android:orientation="vertical">

<ImageView
    android:id="@+id/play_button"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHeight_percent=".5"
    app:layout_constraintWidth_percent=".5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:scaleType="fitXY"
    app:srcCompat="@drawable/rose" />


</android.support.constraint.ConstraintLayout>

完美的它工作了,它解决了我的其他问题,我如何放置图像和按钮而不改变它们的位置和大小非常感谢你的帮助完美的它工作了,它解决了我的其他问题,我如何放置图像和按钮而不改变它们的位置和大小非常感谢你你的帮助