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