SwipeRevealLayout icon indicating copy to clipboard operation
SwipeRevealLayout copied to clipboard

the diffeent height item in listview will comes a problem

Open klower1989 opened this issue 8 years ago • 19 comments

the diffeent height item in listview will comes a problem, see my capture below: device-2016-08-24-105656 and when l load second page and scrooll the Listview: device-2016-08-24-105737 l don't know how to solve this problem, please help me

klower1989 avatar Aug 24 '16 03:08 klower1989

l mean that the diffenent height in listview will lead to other item's height confusion, Sorry, my poor English。。

klower1989 avatar Aug 24 '16 03:08 klower1989

Can you point out more specifically about the issue? I'm not sure what the issue is.

chthai64 avatar Sep 06 '16 19:09 chthai64

l mean that a item in ListVew has a TextView and the TextView has differet lines according to the content, when l swip to left and scroll the ListView, the item height is not right. you can test it in Listview and donnot set a absolute height for the item.

klower1989 avatar Sep 07 '16 07:09 klower1989

Yeap, the same problem. In my case i add new items to list from top. Items with height="wrap_content" in RecyclerView don't mesure their height properly. But I don't use ViewBinderHelper , maybe it will solve the problem.

ArtemMikhaylov avatar Sep 23 '16 08:09 ArtemMikhaylov

Nope, it did not solve the issue.

ArtemMikhaylov avatar Sep 23 '16 09:09 ArtemMikhaylov

Same issue here with Recyclerview as well. Any solutions ?

amarilindra avatar Oct 04 '16 05:10 amarilindra

Is the issue that the slide out layout height isn't matching up to the main list item's layout. I had this issue when I let the list item WRAP_CONTENT so their heights varied, and couldn't get it's height and the revealed layout height to match. If so, I have a solution to it now.

jdavey1996 avatar Dec 11 '16 19:12 jdavey1996

@jdavey1996 what is your solution?

tpfaff avatar Jan 06 '17 06:01 tpfaff

In my arrayadapter for the list item i get the size of the list item view and then adjust the slideout view height to this size: int h1 = slideoutView.getMeasuredHeight(); int h2 = listitemView.getMeasuredHeight();

                ViewGroup.LayoutParams params = listitemView.getLayoutParams();
                params.height = h2;
                deleteView.setLayoutParams(params);

jdavey1996 avatar Jan 12 '17 19:01 jdavey1996

Same issue. There is not any solution yet.

dwlrathod avatar Feb 24 '17 18:02 dwlrathod

@chthai64 @klower1989 I had the same issue. I downloaded the source code of this nice library, changed onMeasure method and now it works like it should. The root view of my RecyclerView' item is SwipeRevealLayout with layout_height="wrap_content"; secondary layout of SwipeRevealLayout have layout_height="match_parent" and main layout of SwipeRevealLayout have layout_height="wrap_content". I didn't check, how it works with other configurations of layouts height's, but hopes correct too)

`@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (getChildCount() < 2) { throw new RuntimeException("Layout must have two children"); }

    final LayoutParams params = getLayoutParams();

    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    int desiredWidth = 0;
    int desiredHeight = 0;

    int wrapChildHeight = 0;
    int wrapChildWidth = 0;

    // first find the largest child
    for (int i = 0; i < getChildCount(); i++) {
        final View child = getChildAt(i);
        final LayoutParams childParams = child.getLayoutParams();
        measureChild(child, widthMeasureSpec, heightMeasureSpec);

        if (childParams.height == LayoutParams.WRAP_CONTENT &&
                (mDragEdge == DRAG_EDGE_LEFT || mDragEdge == DRAG_EDGE_RIGHT))
            wrapChildHeight = Math.max(child.getMeasuredHeight(), wrapChildHeight);
        else
            desiredHeight = Math.max(child.getMeasuredHeight(), desiredHeight);

        if (childParams.width == LayoutParams.WRAP_CONTENT &&
                (mDragEdge == DRAG_EDGE_TOP || mDragEdge == DRAG_EDGE_BOTTOM))
            wrapChildWidth = Math.max(child.getMeasuredWidth(), wrapChildWidth);
        else
            desiredWidth = Math.max(child.getMeasuredWidth(), desiredWidth);

    }
    if (wrapChildHeight != 0) desiredHeight = wrapChildHeight;
    if (wrapChildWidth !=0) desiredWidth =wrapChildWidth;

    // create new measure spec using the largest child width
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(desiredWidth, widthMode);
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(desiredHeight, MeasureSpec.EXACTLY);

    final int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);
    final int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);

    for (int i = 0; i < getChildCount(); i++) {
        final View child = getChildAt(i);
        final LayoutParams childParams = child.getLayoutParams();

        if (childParams != null) {
            if (childParams.height != LayoutParams.WRAP_CONTENT) {
                childParams.height = measuredHeight;
            }

            if (childParams.width == LayoutParams.MATCH_PARENT) {
                childParams.width = measuredWidth;
            }
        }
        measureChild(child, widthMeasureSpec, heightMeasureSpec);
    }

    // taking accounts of padding
    desiredWidth += getPaddingLeft() + getPaddingRight();
    desiredHeight += getPaddingTop() + getPaddingBottom();

    // adjust desired width
    if (widthMode == MeasureSpec.EXACTLY) {
        desiredWidth = measuredWidth;
    } else {
        if (params.width == LayoutParams.MATCH_PARENT) {
            desiredWidth = measuredWidth;
        }

        if (widthMode == MeasureSpec.AT_MOST) {
            desiredWidth = (desiredWidth > measuredWidth)? measuredWidth : desiredWidth;
        }
    }

    // adjust desired height
    if (heightMode == MeasureSpec.EXACTLY) {
        desiredHeight = measuredHeight;
    } else {
        if (params.height == LayoutParams.MATCH_PARENT) {
            desiredHeight = measuredHeight;
        }

        if (heightMode == MeasureSpec.AT_MOST) {
            desiredHeight = (desiredHeight > measuredHeight)? measuredHeight : desiredHeight;
        }
    }

    setMeasuredDimension(desiredWidth, desiredHeight);
}`

OJIer3 avatar May 27 '17 08:05 OJIer3

@OJIer3 Thank so much for your help. It worked for me.

andreluizreis avatar Aug 08 '17 16:08 andreluizreis

Thanks @OJIer3 made my day

mario-dario avatar Sep 10 '17 14:09 mario-dario

@OJIer3 thank you very much, this is exactly what I was looking for!

svetlana-e-petrova avatar Sep 10 '17 20:09 svetlana-e-petrova

@chthai64 Can this fix be added to the library? :)

chrisalbinus avatar Jan 25 '18 11:01 chrisalbinus

I have created a pull request with the code from @OJIer3 https://github.com/chthai64/SwipeRevealLayout/pull/87

@chthai64 please merge this in.

My fork could be referenced until the pull request is merged in like this:
implementation 'com.github.mortenholmgaard:SwipeRevealLayout:Items-with-different-heights-SNAPSHOT'

Requiring this dependency: maven { url 'https://jitpack.io' }

mortenholmgaard avatar Apr 25 '18 09:04 mortenholmgaard

@chthai64 please merge in the PR mentioned above ^^^

brandoFS avatar Jun 19 '18 19:06 brandoFS

Hi @OJIer3 , Thank you so much, its work for me. Brilliant.

avik-capitalnumbers avatar Jun 13 '19 06:06 avik-capitalnumbers

@OJIer3 Спасибо! @mortenholmgaard thanks for sharing

FirstSpectr avatar Oct 08 '20 18:10 FirstSpectr