0
我想使用TransitionAnimation在兩個背景圖像之間切換。TransitionAnimation顯示兩個頂部
下面是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 xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/start_background"/>
<item
android:drawable="@drawable/pause_background"/>
</transition>
start_background和pause_background是兩個不同的圖像,一個代表像一個「播放」按鈕,另一個是「暫停」按鈕。
現在我把這樣的轉變:
private TransitionAnimation transition;
private RelativeLayout screen;
screen = (RelativeLayout)findViewById(R.id.screen);
transition = (TransitionDrawable)screen.getBackground();
現在按壓屏幕時,下面的方法被調用:
transition.startTransition(100);
或者
transition.reverseTransition(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>
start_background.xml:
感謝您的答案,但它沒有奏效,仍然是同樣的問題。 start_background_pressed只是當視圖被觸摸時出現的較暗的圖像。 – user2410644
如果顏色較深,那麼你可能是對的,它在該區域繪製兩次。不知道爲什麼會這樣,我會進一步研究它。在某些情況下,我沒有料到會有兩次抽籤。 –