Android 过渡动画显示两者都在彼此之上

Android 过渡动画显示两者都在彼此之上,android,android-layout,android-drawable,Android,Android Layout,Android Drawable,我正在尝试使用过渡动画在两个背景图像之间切换 下面是main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/screen" android:layout_width="match_parent" android:layout_height

我正在尝试使用过渡动画在两个背景图像之间切换

下面是main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/screen"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MyActivity"
  tools:deviceIds="wear_round"
  android:background="@drawable/background">
</RelativeLayout>
现在按下屏幕时,将调用以下方法:

transition.startTransition(100);

现在的问题是,按下屏幕时,背景图像在

如您所见,第一个图像包含“播放”和“暂停”按钮,它们相互重叠,第二个图像上可能也有两个“播放”图像相互重叠

我不知道怎么会这样,有什么建议吗

以下是两个背景文件:

pause_background.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_pressed="true"
    android:drawable="@drawable/pause_background_pressed"/>

  <item
    android:drawable="@drawable/pause_background_default"/>
</selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_pressed="true"
    android:drawable="@drawable/start_background_pressed"/>

  <item
    android:drawable="@drawable/start_background_default"/>
</selector>

start_background.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_pressed="true"
    android:drawable="@drawable/pause_background_pressed"/>

  <item
    android:drawable="@drawable/pause_background_default"/>
</selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_pressed="true"
    android:drawable="@drawable/start_background_pressed"/>

  <item
    android:drawable="@drawable/start_background_default"/>
</selector>

也许只需将背景设置为
start\u background\u按下开始处的
,在开始处的background.xml就是您所需要的。仅仅将其设置为布局文件中的转换,可能不够聪明,无法处理它。两个人都可能被吸引


然后,您可以在第一次与代码交互时在代码中设置转换。从那时起,我认为它会像预期的那样工作。

谢谢你的回答,但它没有工作,仍然是相同的问题。按下start_background_只是一个较暗的图像,在触摸视图时会出现。如果它较暗,那么您可能是对的,它在该区域上绘制了两次。不知道为什么会这样,我会进一步调查。在某些情况下,我在没有预料到的情况下打了两场平局。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:state_pressed="true"
    android:drawable="@drawable/start_background_pressed"/>

  <item
    android:drawable="@drawable/start_background_default"/>
</selector>