SwipeRevealLayout
SwipeRevealLayout copied to clipboard
the diffeent height item in listview will comes a problem
the diffeent height item in listview will comes a problem, see my capture below:
and when l load second page and scrooll the Listview:
l don't know how to solve this problem, please help me
l mean that the diffenent height in listview will lead to other item's height confusion, Sorry, my poor English。。
Can you point out more specifically about the issue? I'm not sure what the issue is.
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.
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.
Nope, it did not solve the issue.
Same issue here with Recyclerview as well. Any solutions ?
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 what is your solution?
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);
Same issue. There is not any solution yet.
@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 Thank so much for your help. It worked for me.
Thanks @OJIer3 made my day
@OJIer3 thank you very much, this is exactly what I was looking for!
@chthai64 Can this fix be added to the library? :)
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' }
@chthai64 please merge in the PR mentioned above ^^^
Hi @OJIer3 , Thank you so much, its work for me. Brilliant.
@OJIer3 Спасибо! @mortenholmgaard thanks for sharing