我有三个片段,在一个片段中,我有许多imageViews,它们由不同的图像加载。我有一个共享按钮,用于使用Canvas共享所有图像视图的组合。共享功能非常适合首次加载。当我们再次单击共享按钮时,应用程序崩溃。
我想在共享完成/取消后重新加载片段。
有什么办法吗?
这是片段的加载方式
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view1 = inflater.inflate(R.layout.fragment_three,container,false);
View view = inflater.inflate(R.layout.fragment_three,container,false);
return view;
}
public void onViewCreated(View rootView, Bundle savedInstanceState){
super.onViewCreated(rootView, savedInstanceState);
final View v = rootView;
final Context context = null;
...................
}
抱歉,没有空间容纳所有代码
这是用于在视图内共享的代码
img = (ImageView)getView(). findViewById(R.id.imageView15);
collageImage = (ImageView) getView().findViewById(R.id.imageViewcam);
collageImage.destroyDrawingCache();
collageImage.buildDrawingCache();
collageImage.getDrawingCache();
collageImage.setImageResource(android.R.color.transparent);
mBackgroundImage = Bitmap.createBitmap(450,350, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(mBackgroundImage);
img.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ImageView img1 = null;
img1 = (ImageView)getView(). findViewById(R.id.imageViewcam);
img1.destroyDrawingCache();
img1.setDrawingCacheEnabled(true);
img1.buildDrawingCache();
Bitmap bmap1=null;
bmap1 = img1.getDrawingCache();
ImageView img3 = (ImageView)getView(). findViewById(R.id.imageView3);
img3.destroyDrawingCache();
img3.buildDrawingCache();
Bitmap bmap3 = img3.getDrawingCache();
Canvas canvas = new Canvas(bmap1);
canvas.drawBitmap(bmap1, 0f, 0f, null);
float xo51 = img3.getX(); // x-coordinate
float yo51 = img3.getY();
canvas.drawBitmap(bmap3, xo51, yo51, null);
collageImage.setImageBitmap(bmap1);
Drawable mDrawable = collageImage.getDrawable();
Bitmap bitmap = ((BitmapDrawable)mDrawable).getBitmap();
if (Build.VERSION.SDK_INT >= 23)
{
if (checkPermission())
{
try {
File file = new File(getActivity().getExternalCacheDir(),"logicchip.png");
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
file.setReadable(true, false);
final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
intent.setType("image/png");
startActivity(Intent.createChooser(intent, "Share image via"));
} catch (Exception e) {
e.printStackTrace();
}
} else {
requestPermission(); // Code for permission
}
}
else
{
}
}
});
}
我正在寻找的是避免共享错误
错误:画布:尝试在Android中使用回收的位图android.graphics.Bitmap
及其发生在img1.buildDrawingCache();
或重新加载整个片段。
当我们激活fragment1时,将重新加载第三个片段。
希望清楚。
有什么想法吗?
谢谢
答案 0 :(得分:0)
此代码将为您提供帮助
<div [innerHtml]="name">{{name}}</div>
答案 1 :(得分:0)
尝试此操作以进行片段调用。
getSupportFragmentManager().beginTransaction().replace(R.id.activity_main,fragment).commit();