Avoid OutOfMemory crashes on webtoon viewer increasing view holders height

This commit is contained in:
inorichi 2016-01-29 16:17:26 +01:00
parent ea4fa60e01
commit f19889c222
3 changed files with 13 additions and 4 deletions

View File

@ -40,8 +40,17 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
imageView.setMaxScale(10); imageView.setMaxScale(10);
imageView.setOnTouchListener(touchListener); imageView.setOnTouchListener(touchListener);
imageView.setMaxDimensions(maxDim, maxDim); imageView.setMaxDimensions(maxDim, maxDim);
imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
@Override
public void onImageLoaded() {
// When the image is loaded, reset the minimum height to avoid gaps
container.setMinimumHeight(0);
}
});
progressBar.setMinimumHeight(view.getResources().getDisplayMetrics().heightPixels); // Avoid to create a lot of view holders taking all the screen height,
// saving memory and a possible OOM
container.setMinimumHeight(view.getResources().getDisplayMetrics().heightPixels);
container.setOnTouchListener(touchListener); container.setOnTouchListener(touchListener);
retryButton.setOnTouchListener((v, event) -> { retryButton.setOnTouchListener((v, event) -> {

View File

@ -35,7 +35,7 @@ public class WebtoonReader extends BaseReader {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
adapter = new WebtoonAdapter(this); adapter = new WebtoonAdapter(this);
layoutManager = new PreCachingLayoutManager(getActivity()); layoutManager = new PreCachingLayoutManager(getActivity());
layoutManager.setExtraLayoutSpace(getResources().getDisplayMetrics().heightPixels); layoutManager.setExtraLayoutSpace(getResources().getDisplayMetrics().heightPixels / 2);
recycler = new RecyclerView(getActivity()); recycler = new RecyclerView(getActivity());
recycler.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); recycler.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

View File

@ -6,7 +6,7 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="300dp" android:layout_height="match_parent"
android:id="@+id/frame_container"> android:id="@+id/frame_container">
<ProgressBar <ProgressBar