2011-10-03 93 views
6

所以11谷歌推出了以旋轉的ImageView的能力(耶之後,又推出了以動畫這樣的旋轉,耶智能思維的可能性,耶!)在API級別的Android的<API級別旋轉的ImageView 11

但我應該如何去使用例如旋轉ImageView API級別8?我不能像上面描述的那樣使用setRotation()。

回答

2

我開始創建位圖和旋轉畫布/矩陣,然而,這不是一個好的解決方案。如果條件得到滿足,最後結束只是交換drawable。我應該說這是一個ExpandableListView,其中單元在繪製時被重用。

if (isExpanded) { 
     ImageView view = (ImageView) convertView.findViewById(R.id.ImageView); 
     view.setImageResource(R.drawable.quickactions_button_normal_down); 
    } 

    if (!isExpanded) { 
     ImageView view = (ImageView) convertView.findViewById(R.id.ImageView);   
     view.setImageResource(R.drawable.quickactions_button_normal); 
    } 

我不是通常的Android開發者,但我真的很驚訝,這是可能的動畫旋轉,而不是靜態設置一個繪製的旋轉。從邏輯上講,第一個是第二個子集,而不是其他方法。

7

RotationAnimation是自API級別本1

RotateAnimation animation = new RotateAnimation(from, to, 
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
animation.setInterpolator(new LinearInterpolator()); 
animation.setDuration(1); 
animation.setFillAfter(true); 

imageView.startAnimation(animation); 
+1

是的。即使持續時間設置爲1,這仍然會顯示爲動畫。同時在ExpandableTableView中使用此方法時,單元格在繪圖時重複使用會導致代價高昂,而滾動列表時「快速」動畫看起來很奇怪。我最終只是交換了drawable。 – sebrock