我正在做一个简单的android程序,我想在点击我的主XML文件的按钮后从图像数组中依次播放图像。 但程序关闭不幸。从图像数组中播放图像
代码:
package com.example.play_image;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
//import android.view.View;
//import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
int imageList[]={R.drawable.exam_a,R.drawable.exam_b,R.drawable.exam_c,
R.drawable.exam_d,R.drawable.exam_e};
ImageView letter;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void play_image(){
for(int i=0;i<5;i++){
letter.setBackgroundResource(imageList[0]);
}
}
XML文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="158dp"
android:background="@drawable/exam_a"
android:onClick="play_image" />
</RelativeLayout>
我还有一个问题:
- 我要玩图像就像每个图像无线会出现在屏幕上并停留一段时间(如10秒),然后出现另一个。我应该怎么做?
- 我该怎么做才能在该图像上添加动画?
我应该创造我的XML文件名为 “myImageView” 任何ImageView的? – STM 2014-10-03 19:25:04