簡體   English   中英

如何使用 Android Java 實現重復的全周期 imageview 旋轉?

[英]How to achieve repetitive full cycle imageview rotation with Android Java?

我在我的 android 應用程序中有一個ImageView和一個按鈕,每次新單擊時將圖像逐漸向左旋轉 90 度。 現在,在應用任何旋轉之前,我已經處理了 object 到原始 position 的旋轉,當我再次單擊旋轉按鈕時循環旋轉效果繼續,一個奇怪的旋轉應用到 ZA8CFDE6331BD59EB2AC96F8911C4 而不是旋轉90 degrees left of the current position, it does some weird rotation that can be confirmed by implementing this code below that am using and needs reforming... The code is Android Java formatted in Xamarin Standards( The methods start with uppercase letters )

代碼

private void Rotate_Click(object sender, EventArgs e)
        {
            rotation_count += 1;
            //initialize the image transformation matrix
            /*
             we need four states for this rotation
            1 for 90
            2 for 180
            3 for 270 and 
            4 for 360 for full rotation
             
             */
            //I need help with this structure to make it implement the infinite
             //rotation to the left loop which means provided the user has clicked the 
             //rotate button it should keep adjusting the current position by 90deg
            if (rotation_count == 1)
            {
                imageView.Animate().Rotation(90f).Start();
            }else if(rotation_count == 2)
            {
                imageView.Animate().Rotation(180f).Start();
            }else if(rotation_count == 3)
            {
                imageView.Animate().Rotation(270f).Start();
            }
            else
            {
                imageView.Animate().Rotation(360f).Start();
                //reset the rotation_counter
                rotation_count = 0;
            }
            
        }

目標

我想實現這個 ImageView object 的全周期旋轉,無論用戶單擊按鈕的次數它應該保持向左旋轉 90 度,即使在全周期旋轉完成后,如果用戶再次單擊按鈕,它應該旋轉圖像向左 90 度以創建由按鈕單擊觸發的無限旋轉循環,謝謝。

在嘗試自己弄清楚之后,我終於設法想出了一個解決方法。 只需將計數器乘以您希望在每次單擊時間隔的度數。

private void rotate_click(object sender, EventArgs e){
            if (rotation_count > 0)
            {
                imageView.Animate().Rotation(rotation_count * 90).Start();
                
            }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM