sephiroth74 / HorizontalVariableListView

Horizontal list view for Android which allows variable items widths
859 stars 282 forks source link

requestLayout() "improperly called" on Lollipop #93

Open elroid opened 10 years ago

elroid commented 10 years ago

Hello, I have no problems with this library on a Samsung Galaxy Note 3 or Sony Xperia Z (KitKat), or Galaxy Nexus (JellyBean), but whenever i run it on a Nexus 5 with Lollipop, the scrolling does not function and i get the following repeating continuously for as long as the activity is open.

W/View﹕ requestLayout() improperly called by it.sephiroth.android.library.widget.HListView{227055a5 VFED..C. .F....ID 0,18-1020,258 #7f08015d app:id/galleryListView} during layout: running second layout pass
W/View﹕ requestLayout() improperly called by it.sephiroth.android.library.widget.HListView{227055a5 VFED..C. .F...... 0,18-1020,258 #7f08015d app:id/galleryListView} during second layout pass: posting in next frame

I am using the HListView as a header on a ListView. Note, i have found that if i scroll the list down a bit and come back, it seems to fix itself - no more errors and the scrolling works as expected, which is the only thing that keeps this from being a showstopper.

Any idea what could be causing this error?

ticofab commented 9 years ago

I am getting the same issue. Was it solved somehow?

elroid commented 9 years ago

No, i'm afraid i never received any response! I attempted to fork it and fix it myself but ran out of time simply trying to diagnose the issue...

abhishekBansal commented 9 years ago

facing same issue on MotoG 2 Lolipop working fine with 4.4.4 Kitkat (Moto E)

DennisBranchOut commented 9 years ago

Try this: http://stackoverflow.com/questions/24598977/android-requestlayout-improperly-called/26262615#26262615

Although it didn't work for me. This is a custom list view I am using, though.

skauss commented 9 years ago

Hi, I have exact the same problem. Only difference is : Android 4.4.4 is OK But on Android 5.1.1 I get the
W/View(10304): requestLayout() improperly called by it.sephiroth.android.library.widget.HListView

Error an the scroll view in in one endless loop until I press the back button.

Any idea to get a work around ?

Regards Stephan

skauss commented 9 years ago

Hi, I changed in class HListView.java the method

protected void onFocusChanged( boolean gainFocus, int direction, Rect previouslyFocusedRect) 

around line 3544 At the end of this method requestLayout(); is called.

Old Code ::

        if ( closetChildIndex >= 0 ) {
            setSelectionFromLeft( closetChildIndex + mFirstPosition, closestChildLeft );
        }
        else {
            if ( LOG_ENABLED ) {
                Log.d( LOG_TAG, "requestLayout : onFocusChanged " );
            }

            requestLayout();
        }

New Code ::

            if ( gainFocus && previouslyFocusedRect != null ) {
                if ( LOG_ENABLED ) {
                    Log.d( LOG_TAG, "requestLayout : onFocusChanged " );
                }

                requestLayout();
            }
            else {
                if ( LOG_ENABLED ) {
                    Log.d( LOG_TAG, "SKIP : requestLayout : onFocusChanged " );
                }
            }

This break the repeating loop "08-24 14:26:32.466: W/View(4327): requestLayout() improperly called by ". I have no idea if I break anything else but it works for me so fare. I am interested if this helps any where else or if I do a big mistake

Regards Stephan

aichengrui00 commented 8 years ago

hao quest?

rockerhieu commented 8 years ago

You should wrap the calling to requestLayout() with this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
  if (!isInLayout()) {
    requestLayout();
  }
}
sheharyarn commented 7 years ago

My code is completely unrelated to this project, but @rockerhieu solution still worked for me. Thanks.

rigortek commented 6 years ago

When I enable TextView marquee, I met the same issue, and rockerhieu's code solved my issue.