Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.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 - Fatal编程技术网

Android 当活动返回到后台时,强制重新绘制视图时该怎么办

Android 当活动返回到后台时,强制重新绘制视图时该怎么办,android,Android,救命啊 我想将应用程序中的页面重新绘制回背景,但addView方法不起作用,系统没有调用onDraw方法 我尝试调用invalidate方法和requestLayout方法,但没有任何效果。有办法解决吗?这是主要代码 private Handler handler = new Handler(Looper.getMainLooper()); FragmentLayout view1 = (FrameLayout)getWindow().getDecorView(); @Override pro

救命啊 我想将应用程序中的页面重新绘制回背景,但addView方法不起作用,系统没有调用onDraw方法

我尝试调用invalidate方法和requestLayout方法,但没有任何效果。有办法解决吗?这是主要代码

private Handler handler = new Handler(Looper.getMainLooper());
FragmentLayout view1 = (FrameLayout)getWindow().getDecorView();

@Override
protected void onPause() {
    super.onPause();
    handler.post(new Runnable() {
        @Override
        public void run() {
            addRenderScriptBitmap();
        }
    });
    getWindow().getDecorView().findViewById(android.R.id.content).invalidate();
    getWindow().getDecorView().findViewById(android.R.id.content).requestLayout();

}


private void addRenderScriptBitmap() {
    view1.setDrawingCacheEnabled(true);
    view1.buildDrawingCache();
    Bitmap bitmap = view1.getDrawingCache();

    ImageView imageView = new ImageView(MainActivity.this);
    imageView.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    imageView.setImageBitmap(renderScriptBitmap(bitmap, MainActivity.this, 16.f));
    view1.addView(imageView);//This method does not work
}

public Bitmap renderScriptBitmap(Bitmap sentBitmap, Context context, float radius) {
    Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);


    final RenderScript rs = RenderScript.create(context);
    final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
            Allocation.USAGE_SCRIPT);
    final Allocation output = Allocation.createTyped(rs, input.getType());
    final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setRadius(radius /* e.g. 3.f */);
    script.setInput(input);
    script.forEach(output);
    output.copyTo(bitmap);
    return bitmap;
}

我希望应用程序在如下情况下返回到后台:

android:不允许在应用程序处于后台时更新视图我希望应用程序在如下情况下返回后台:输入图像描述我希望应用程序在如下情况下返回后台:输入图像描述
@Override 
protected void onResume() { 
    super.onResume(); 
    handler.post(new Runnable() 
    {
        @Override 
        public void run() 
        { 
            addRenderScriptBitmap(); 
        } 
    }); 
    getWindow().getDecorView().findViewById(android.R.id.content).invalidate();
    getWindow().getDecorView().findViewById(android.R.id.content).requestLayout();
}