1
當我目前正與一組的ToggleButtons與多個國家的背景資源和旋轉動畫工作。一切工作正常,直到一個切換按鈕被按下,在這種情況正在發生:安卓:背景繪製不旋轉旋轉切換按鈕
- 當按鈕被聚焦,它得到重新繪製,但在原來的狀態,因爲它是在旋轉0
- 當該按鈕被釋放,它試圖用真實值背景重新繪製新背景,但是由於使用原始切換按鈕高度作爲寬度,所以圖像寬度被裁剪。
- 當按鈕被再次聚焦,它發生了同樣的問題:1)。
- 當按鈕被釋放時,它得到正確重繪。
到目前爲止,我現在問題是,原來的drawables不旋轉,因此這種行爲。我目前的解決方案是爲每個旋轉使用三個不同的切換按鈕(90°,0°,-90°),動畫和隱藏當前按鈕,然後顯示新按鈕(使用相同的drawable並使用XML旋轉它們標籤),但我覺得是一種累贅......
下面是用於90°動畫XML:
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fromDegrees="0"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="250"
android:fillAfter="true"
android:fillEnabled="true" >
</rotate>
的XML的切換按鈕背景:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/record_button_on_pressed"
android:state_checked="true" android:state_pressed="true"/>
<item android:drawable="@drawable/record_button_pressed" android:state_checked="true"
android:state_focused="false"/>
<item android:drawable="@drawable/record_button_on_press"
android:state_checked="false" android:state_pressed="true"/>
<item android:drawable="@drawable/record_button" android:state_checked="false"
android:state_focused="false"/>
</selector>
而且用於旋轉視圖的代碼:
RotateAnimation rotate = (AnimationUtils.loadAnimation(this,
R.anim.rotation90deg);
startStopRecording.startAnimation(rotate);
希望你們能幫助我。
一些代碼會有幫助。 –
你可以展示你如何做旋轉?如果您旋轉按鈕,那麼繪圖板也應該旋轉。 – Eluvatar
drawable正確旋轉,但是當執行焦點或狀態更改時,視圖顯示錯誤。還在原始問題上添加了相應的代碼。 – vicmns