Android:实现幻灯片放映

Android:实现幻灯片放映,android,slideshow,Android,Slideshow,我正在尝试在我的android应用程序中实现幻灯片放映。我的xml文件中有一个imageview和一个text视图。我想让imageview显示一些图像的幻灯片。图像存储在可绘制的hdpi中。当我打开此页面时,只显示文本视图,而不显示幻灯片。没有一张图片显示出来。 下面是同样的java文件 package abc.xys; import android.annotation.SuppressLint; import android.app.Activity; import android.os

我正在尝试在我的android应用程序中实现幻灯片放映。我的xml文件中有一个imageview和一个text视图。我想让imageview显示一些图像的幻灯片。图像存储在可绘制的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);

    }

}
包abc.xys;
导入android.annotation.SuppressLint;
导入android.app.Activity;
导入android.os.Bundle;
导入android.os.Handler;
导入android.os.Message;
导入android.widget.ImageView;
导入android.widget.TextView;
公开课的愿望扩展了活动{
图像视图幻灯片;
文本视图消息;
int i=0;
int imgid[]={R.drawable.friends01,R.drawable.friends02,R.drawable.friends03,R.drawable.friends04,R.drawable.friends05};
RefreshHandler RefreshHandler=新的RefreshHandler();
@SuppressLint(“HandlerLeak”)
类RefreshHandler扩展处理程序{
@凌驾
公共无效handleMessage(消息消息消息){
//TODO自动生成的方法存根
Wishes.this.updateUI();
}
公共无效睡眠(长延迟毫秒){
此.removeMessages(0);
sendMessageDelayed(获取消息(0),delayMillis);
}
};
公共void updateUI(){
int currentInt=Integer.parseInt((字符串)msg.getText())+10;

如果(CurrentInt)尝试使用android:srcType=“centerCrop”
或您的
ImageView
中的其他东西,我想告诉您的另一件事是,我使用了相同的代码来实现幻灯片放映,当时它工作了。但现在它不工作。使用android:srcType=“centerCrop”给出以下错误:错误:在包“android”中找不到属性“srcType”的资源标识符
<?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>