2011-06-27 4 views
1

AnimationDrawableを正常に動作させるのに問題はありませんが、ImageViewのフルサイズ(常にlayout_height、width to fill_parent)になります。興味深いことに、layout_height、widthを他のもの(wrap_content、特定のピクセルなど)に設定すると、アニメーションがまったく表示されません。 Image setImageまたはsetBackgroundImage、同じ結果を使用しても問題ありません。ScaleTypeに影響するか、またはAnimationDrawableにマトリックスを適用する

AnimationDrawablesのリスト全体に既存のMatrixを適用できるのは理想的でしょう。ここで

は私もこの問題を抱えている... `

  wxChartAnimation = new AnimationDrawable(); 
      int numCharts = subChart.getChartCount(); 
      for (int i=0; i < numCharts; i++) { 
       WeatherChart.BaseChart baseChart = subChart.getBaseChart(i); 
       File file = new File(baseChart.localPath); 
       if (file != null && file.exists()) { 
        Drawable d = Drawable.createFromPath(baseChart.localPath); 
        if (d != null) { 
         if (wxChartAnimation != null) { 
          wxChartAnimation.addFrame(d,250); 
         } 
        } 
       } 
      } 

      wxChartAnimation.setOneShot(false); 
      wxChartImage.setImageDrawable(wxChartAnimation); 
      wxChartAnimation.start();` 

答えて

0

コードです。その価値については、私の目的のためにハックの回避策を見つけました。 AnimationDrawableを "new AnimationDrawable()"を使用してプログラムで作成すると、ImageViewのscaleTypeを尊重しないようです。ただし、.anim xmlリソースをその参照リソースドロワブル内のフレームのリストと共に使用すると、ImageViewのscaleTypeに従って、最初のイメージのサイズとアニメーションのサイズを適切に調整します。 assetsフォルダからAnimationDrawableに画像をロードしようとしているので、私はコードからそれを行う必要がありました。に続いて

<?xml version="1.0" encoding="utf-8"?> 

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="true"> 
    <item android:drawable="@drawable/empty_slide" android:duration="0" /> 
</animation-list> 

:(empty_slide私はアニメーションの残りのために使用されるサイズの透明なイメージです)解像度で

/アニメーション/ empty.xml:私は次のことをやってしまいました私のjavaファイル:

imageView.setImageResource(R.anim.empty); 
AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getDrawable(); 
animationDrawable.addFrame(Drawable.createFromStream(context.getAssets().open(drawablePath), null),animationDuration); 
// Add the rest of the frames 
... 
animationDrawable.start(); 

私はあなたがより良い方法を発見した場合は聞いてみたい...

0

私はいくつかの別の方法を見つけるんだ...

問題点 - "new AnimationDrawable()"は設定されません。CurrentDrawable => AnimationDrawableの高さと幅を設定しません。

私は問題をこのように解決:その後

protected void playFrameAnimationWithCurrentFrame(final ImageView ImView,final AnimationDrawable AnimDrawable){ 
    ImView.post(new Runnable(){ 
     public void run(){ 
      AnimDrawable.start(); 
     }});//We start the animation so that we have the current frame on which the matrix for mapping is based 

    Thread t = new Thread() { 
     @Override 
     public void run() { 
      while(AnimDrawable.getCurrent()==null){//wait for the current frame to appear      
       try { 
        Thread.sleep(50); 
       } catch (InterruptedException e) { 
        e.printStackTrace(); 
       } 
      } 

      ImView.post(new Runnable(){//stop the current animation to assign animation to view and restart 
       public void run(){ 
        AnimDrawable.stop(); 
       }}); 
       runOnUiThread(new Runnable() { 
       @Override 
       public void run() { 
        ImView.setImageDrawable(AnimDrawable);} 
      }); 

      ImView.post(new Runnable(){ 
       public void run(){ 
        AnimDrawable.start();}}); 
      interrupt(); 
     }}; 
    t.start(); 
} 

を、アニメーションは、我々が以前にImageViewの上に設置マトリックス、で再生されます。

この方法では、.xmlリソースファイルは必要ありません。

関連する問題