2012-02-16 15 views
0

このコードを書きましたが、結果として致命的な例外が発生しました。すべての例外を処理しました。なぜthis.andのイメージビューアにアニメーションを適用するのですか?イメージビューでアニメーションを適用する方法

主な活動

public class AnimViewActivity extends Activity { 
    /** Called when the activity is first created. */ 
    Button b; 
    ImageView iv; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     b=(Button)findViewById(R.id.but); 
     try{ 
     b.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       iv=(ImageView)findViewById(R.id.im); 
       iv.setVisibility(ImageView.VISIBLE); 
       iv.setBackgroundResource(R.drawable.ic_launcher); 
       iv.startAnimation(new Anmatam()); 
      } 
     }); 
     } 
     catch(Exception e){ 
      e.printStackTrace(); 
     } 
    } 
} 

アニメーション

public class Anmatam extends Animation { 
float centerx,centery; 
    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     // TODO Auto-generated method stub 

     super.applyTransformation(interpolatedTime, t); 
     try{ 
     Matrix mt=t.getMatrix(); 
     mt.setScale(interpolatedTime, interpolatedTime); 
     mt.preTranslate(-centerx,-centery); 
     mt.postTranslate(centerx, centery); 
     } 
     catch (Exception e) { 
      // TODO: handle exception 
      e.printStackTrace(); 
     } 
    } 

    @Override 
    public void initialize(int width, int height, int parentWidth, 
      int parentHeight) { 
     // TODO Auto-generated method stub 
     super.initialize(width, height, parentWidth, parentHeight); 
     try{ 
     centerx=width/0.2f; 
     centery=height/0.2f; 
     setDuration(2000); 
     setFillAfter(true); 
     setInterpolator(new LinearInterpolator()); 
     } 
     catch(Exception e){ 
      e.printStackTrace(); 
     } 
    } 

} 

マニフェスト

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.my.net.pro" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="10" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".AnimViewActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".Anmatam"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 

      </activity> 
    </application> 

</manifest> 
+0

で見つからなかった場合

は、あなたのスタックトレースを追加してください起こる可能性があります。 – Olegas

答えて

0

あなたはcatchin'しませんでした潜在的なNullPointerExceptionここに:iv.setVisibility(ImageView.VISIBLE);。何ImageViewが前の行

関連する問題