次の質問を立てさせていただきます。
理由は職業訓練校の授業の内容で起きた原因不明のバグで、これを解決しないと授業が停滞してしまい、深刻な問題になってしまうためです。
(一人でも停滞していると授業が進まないスタイルになっているので・・・)
今回もSBCreativeの基礎からのAndroidからの質問です。
今回はAndroid の アニメーションを使い、画像をスケールしたりトランスレーションしたりしているのですが、
なぜか回転(rotate)だけ結果が回転せず、一瞬画像が消えてそして指定時間後にまた表示されるという不可解な結果になってしまいます。
最初は画像の問題も疑ったのですが度の画像にしても同じバグが発生するのでコードのどこかに問題があると認識しました。
以下、その該当部分のコードです。
Activity
package jp.denpa.animationsample;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class AnimationSampleActivity extends ActionBarActivity implements View.OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.alpha).setOnClickListener(this);
findViewById(R.id.rotate).setOnClickListener(this);
findViewById(R.id.scale).setOnClickListener(this);
findViewById(R.id.translate).setOnClickListener(this);
}
public void onClick(View v){
Animation animation = null;
ImageView image1 = (ImageView) findViewById(R.id.dodge);
switch(v.getId()){
case R.id.alpha:
animation = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
break;
case R.id.rotate:
animation = AnimationUtils.loadAnimation(this, R.anim.anim_rotate);
break;
case R.id.scale:
animation = AnimationUtils.loadAnimation(this, R.anim.anim_scale);
break;
case R.id.translate:
animation = AnimationUtils.loadAnimation(this, R.anim.anim_translate);
break;
}
image1.startAnimation(animation);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.animation_sample, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%">
</rotate>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.denpa.animationsample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".AnimationSampleActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>