Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 屏幕图像视图中的备用图像_Android_Android Asynctask_Imageview_Android Imageview - Fatal编程技术网

Android 屏幕图像视图中的备用图像

Android 屏幕图像视图中的备用图像,android,android-asynctask,imageview,android-imageview,Android,Android Asynctask,Imageview,Android Imageview,我的可绘制文件夹中有两个图像,我希望每x次在视图中交替显示这两个图像。 我尝试使用Asynctask,但不起作用,也找不到解决方案 我的xml代码 <ImageView android:id="@+id/imageload" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" a

我的可绘制文件夹中有两个图像,我希望每x次在视图中交替显示这两个图像。 我尝试使用Asynctask,但不起作用,也找不到解决方案

我的xml代码

<ImageView
    android:id="@+id/imageload"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="64dp"
    android:adjustViewBounds="false"
    android:baselineAlignBottom="false"
    android:contentDescription="@string/imatge"
    android:cropToPadding="false"
    android:fitsSystemWindows="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:src="@drawable/hdtitol2" />
主类包含带有异步代码的de类

public class ModifyImage extends AsyncTask<Void, Void, Void> {

    ImageView img= (ImageView)findViewById(R.id.imageload);

    @Override
    protected void onPreExecute(){

    }
    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        int i = 0;
        boolean opt = true;
        boolean exit = false;
        while(!exit){
            if(i == 1000){
                i = 0;
                if(!opt){
                    img.setImageResource(R.drawable.blackhdtitol2);
                    opt =true;
                }else{
                    opt = false;
                    img.setImageResource(R.drawable.hdtitol2);
                }
            }
            i++;
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void i){

    }

}
公共类ModifyImage扩展异步任务{
ImageView img=(ImageView)findViewById(R.id.imageload);
@凌驾
受保护的void onPreExecute(){
}
@凌驾
受保护的Void doInBackground(Void…参数){
//TODO自动生成的方法存根
int i=0;
布尔opt=true;
布尔退出=假;
当(!退出){
如果(i==1000){
i=0;
如果(!opt){
img.setImageResource(R.drawable.blackhdtitol2);
opt=true;
}否则{
opt=false;
img.setImageResource(R.drawable.hdtitol2);
}
}
i++;
}
返回null;
}
@凌驾
后期执行时受保护的void(void i){
}
}
这样做

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        Integer tag = (Integer) img.getTag();
        if(tag == R.drawable.blackhdtitol2){
                img.setImageResource(R.drawable.blackhdtitol2);
                img.setTag(R.drawable.blackhdtitol2);
            }else{
                img.setImageResource(R.drawable.hdtitol2);
                img.setTag(R.drawable.hdtitol2);
            }
    }
}, 60*1000);

最后,我找到了一个可能的解决方案,描述了我关于这个问题的所有反java代码

我找到的解决方案是创建一个新类

public class RepeatingThread implements Runnable {

    private final Handler mHandler = new Handler();

    public RepeatingThread() {

    }

    @Override
    public void run() {
        final ImageView img = (ImageView) findViewById(R.id.imageload);

        if(img.getVisibility() == View.INVISIBLE ){
            img.setVisibility(View.VISIBLE);
        }else{
            img.setVisibility(View.INVISIBLE);
        }
        mHandler.postDelayed(this, 1000);       
    }
}
以及创建时函数中的代码:

final Thread t = new Thread(new RepeatingThread());
    t.start();
final Thread t = new Thread(new RepeatingThread());
    t.start();