Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 5 additions & 49 deletions library/src/main/java/com/daimajia/swipe/SwipeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.AdapterView;
import android.widget.FrameLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SwipeLayout extends ViewGroup{
public class SwipeLayout extends FrameLayout {

private ViewDragHelper mDragHelper;

Expand Down Expand Up @@ -588,57 +589,12 @@ void layoutLayDown(){

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);

int width, height;

if(heightMode == MeasureSpec.UNSPECIFIED)
heightSize = Integer.MAX_VALUE;

if(widthMode == MeasureSpec.UNSPECIFIED)
widthSize = Integer.MAX_VALUE;

measure(getSurfaceView(), widthSize, heightSize);
measure(getBottomView(), widthSize, heightSize);

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

if(mDragEdge == DragEdge.Left || mDragEdge == DragEdge.Right)
mDragDistance = getBottomView().getMeasuredWidth();
else
mDragDistance = getBottomView().getMeasuredHeight();

width = Math.max(getSurfaceView().getMeasuredWidth(), getBottomView().getMeasuredWidth());
height = Math.max(getBottomView().getMeasuredHeight(), getBottomView().getMeasuredHeight());

setMeasuredDimension(width, height);
}

private void measure(View child, int maxWidth, int maxHeight){
LayoutParams lp = child.getLayoutParams();
int childWidthSpec, childHeightSpec;
if(lp.width == LayoutParams.WRAP_CONTENT){
childWidthSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST);
}else if(lp.width == LayoutParams.MATCH_PARENT){
childWidthSpec = MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.EXACTLY);
}else{
childWidthSpec = MeasureSpec.makeMeasureSpec(Math.min(maxWidth, lp.width), MeasureSpec.EXACTLY);
}

if(lp.height == LayoutParams.WRAP_CONTENT){
childHeightSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST);
}else if(lp.height == LayoutParams.MATCH_PARENT) {
if(maxHeight == Integer.MAX_VALUE){
maxHeight = dp2px(80);
}
childHeightSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.EXACTLY);
}else{
childHeightSpec = MeasureSpec.makeMeasureSpec(Math.min(maxHeight, lp.height), MeasureSpec.EXACTLY);
}

child.measure(childWidthSpec, childHeightSpec);

}

@Override
Expand Down Expand Up @@ -1058,4 +1014,4 @@ private Rect computeBottomLayDown(DragEdge dragEdge){
private int dp2px(float dp){
return (int) (dp * getContext().getResources().getDisplayMetrics().density + 0.5f);
}
}
}