2011-11-17 66 views
3

我有一個內部繪圖的圖像視圖。這可繪製是一個類似於存在於進度對話框的環:如何旋轉drawable而不是imageView本身?

loading_ring:

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="ring" 
    android:innerRadiusRatio="3" 
    android:thicknessRatio="8" 
    android:useLevel="false"> 
    <size 
     android:width="20dip" 
     android:height="20dip"/> 

    <gradient 
     android:type="sweep" 
     android:useLevel="false" 
     android:startColor="#4c737373" 
     android:centerColor="#4c737373" 
     android:centerY="0.50" 
     android:endColor="#ffffffff"/> 
</shape> 

爲了旋轉該環我已經創建了一個旋轉的動畫像這樣:

<rotate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" 
    android:toDegrees="359" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:repeatCount="infinite" 
    android:duration="1000" 
    android:interpolator="@android:anim/linear_interpolator" /> 

但當我在imageView上應用動畫時:

this.cameraView.setAnimation(AnimationUtils.loadAnimation(this,R.anim.loadinganimation)); 

all imageVie w正在旋轉。我只想旋轉戒指(imageview的src)我怎麼能實現這一目標?

感謝

回答

1

讓兩週地分居的看法和使用FrameLayout遏制他們。這樣你就可以將動畫應用到鈴聲而不是其他的小部件。

編輯:

我猜你是放置ImageView內部形狀與android:src和設置別的東西與android:background。如果是這樣的話,而不是使用ImageView你可以嘗試:

<FrameLayout> 
    <ImageView with the background> 
    <ImageView with JUST the shape> 
</FrameLayout> 

<FrameLayout android:background="blah"> 
    <ImageView with JUST the shape> 
</FrameLayout> 
+0

你能詳細介紹一下你的答案嗎? 「製作兩個分開的視圖」是什麼意思,兩個視圖是什麼? – grunk

+0

@grunk:我剛剛編輯了我的答案。 – Macarse

+0

好的感謝您的更新。我已經在使用這個「技巧」,但我希望有一個更清潔的方法。無論如何都要上傳,稍等一會再接受;) – grunk

2
// load the origial BitMap (500 x 500 px) 
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
     R.drawable.android); 

int width = bitmapOrg.width(); 
int height = bitmapOrg.height(); 

// createa matrix for the manipulation 
Matrix matrix = new Matrix(); 

// rotate the Bitmap 
matrix.postRotate(45); 

// recreate the new Bitmap 
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 
        width, height, matrix, true); 

// make a Drawable from Bitmap to allow to set the BitMap 
// to the ImageView, ImageButton or what ever 
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); 

// set the Drawable on the ImageView 
imageView.setImageDrawable(bmd); 

詳細檢查了這一點。

http://www.anddev.org/resize_and_rotate_image_-_example-t621.html

+0

這個解決方案有一個一次旋轉的事情。我不確定這是否會對無限制(及時)旋轉有用。 – grunk