我正在尝试在我的Android应用中实现幻灯片。我的xml文件中有一个imageview和一个文本视图。我希望该imageview显示一些图像的幻灯片。图像存储在drawable-hdpi中。当我打开此页面时,只显示文本视图而不是幻灯片显示。没有显示单个图像。 以下是相同的java文件。
package abc.xys;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import android.widget.TextView;
public class Wishes extends Activity {
ImageView slide;
TextView msg;
int i=0;
int imgid[]={R.drawable.friends01,R.drawable.friends02,R.drawable.friends03,R.drawable.friends04,R.drawable.friends05};
RefreshHandler refreshHandler=new RefreshHandler();
@SuppressLint("HandlerLeak")
class RefreshHandler extends Handler{
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
Wishes.this.updateUI();
}
public void sleep(long delayMillis){
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
};
public void updateUI(){
int currentInt=Integer.parseInt((String)msg.getText())+10;
if(currentInt<=100){
refreshHandler.sleep(2000);
msg.setText(String.valueOf(currentInt));
if(i<imgid.length){
slide.setImageResource(imgid[i]);
// slide.setPadding(left, top, right, bottom);
i++;
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.wishes_template);
slide = (ImageView) findViewById(R.id.slideshow);
msg = (TextView) findViewById(R.id.message);
}
}
xml文件(wishes_template)是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/slideshow_layout"
>
<ImageView android:id="@+id/slideshow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20dp"
></ImageView>
<TextView android:text="10"
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
提前致谢!