0
以下是ViewPager中使用的PageF
片段的來源& PageAdapter。如何使用Fragment在pageAdapter中回收位圖?在android中
public class PageF extends Fragment {
public static final String ARG_PARAM1 = "bitmap";
public static PageF newInstance(int id) {
PageF fragment = new PageF();
Bundle args = new Bundle();
args.putInt(ARG_PARAM1, id);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.preview_image, container, false);
}
@Override
public void onViewCreated(View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ImageView imageView = (ImageView) view;
Bitmap bitmap = BitmapFactory.decodeResource(
getResources()
, getArguments().getInt(ARG_PARAM1)
);
imageView.setImageBitmap(bitmap);
}
}
如何回收該位圖?有時,在某些設備中,它發生內存不足。 :(
非常感謝! – myoungjin