Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Studio designer cannot render RecyclerViewPager element if height isnt't specified/memory leak when running an app #126

Open
mantic87ja opened this issue Oct 4, 2016 · 2 comments

Comments

@mantic87ja
Copy link

mantic87ja commented Oct 4, 2016

There is a problem with the latest version of library, when for example you put RecyclerViewPager in this structure:

<LinearLayout 
android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="horizontal">

        <View android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="2"/>


        <RelativeLayout android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="6">

            <com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager
                    android:id="@+id/pager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerInParent="true"/>

        </RelativeLayout>

        <View android:layout_width="0dp"
              android:layout_height="match_parent"
              android:layout_weight="2"/>

    </LinearLayout>

It seems that in this case it cannot measure it's own height so Android Studio gets stuck with these exception:
java.util.concurrent.TimeoutException: Preview timed out while rendering the layout...
....
...
at com.lsjwzh.widget.recyclerviewpager.RecyclerViewPagerAdapter.onCreateViewHolder(RecyclerViewPagerAdapter.java:26)

Also, if you run an application you'll get memory leak and it is going to crash immediately. In some older versions when we used lib as a standalone library and added it as a module to our project everything was working fine.

Please, check out these and try to fix this issue.

@Marcel50506
Copy link

+1! I've got this same issue, it's very annoying. The app keeps measuring/getting item count, causing a memory leak.

Beside that, Android Studio also has a memory leak when trying to preview the XML layout, probably due to the same problem.

My layout looks similar, using LinearLayout with weights:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <com.lsjwzh.widget.recyclerviewpager.LoopRecyclerViewPager
            android:id="@+id/first_vp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
     </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <com.lsjwzh.widget.recyclerviewpager.LoopRecyclerViewPager
            android:id="@+id/second_vp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
     </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <com.lsjwzh.widget.recyclerviewpager.LoopRecyclerViewPager
            android:id="@+id/third_vp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
     </RelativeLayout>
</LinearLayout>

@Marcel50506
Copy link

For those encountering the same issue: When using weights, you normally set the width or height to 0dp. For me, this made both my Android Studio and my app leak memory. When setting it to 1dp, this seems to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants