次のコードでサンプル プログラムをアニメーション化しようとしています。
AnimationDrawable animation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
ImageView animatedImage = (ImageView) findViewById(R.id.animation);
animatedImage.setBackgroundResource(R.drawable.animate_bag);
animation = (AnimationDrawable) animatedImage.getBackground();
}
public void startAnimate(View v)
{
if (animation != null)
animation.start();
} //eof OnClick
XML ファイルは次のとおりです。
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate"
android:onClick="startAnimate" />
<ImageView
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/animate_bag" />
</LinearLayout>
私が抱えている問題は、animateImage.getBackground() が null を返すことです。
ヒントをいただければ幸いです:-)
ありがとう、サイモン