Skip to content

Commit 37b341f

Browse files
author
jfeinstein10
committed
Having issues with laying out the 'window' in the CustomAboveView
1 parent 716c3b1 commit 37b341f

File tree

4 files changed

+47
-35
lines changed

4 files changed

+47
-35
lines changed

library/src/com/slidingmenu/lib/CustomViewAbove.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import android.widget.Scroller;
3737

3838
public class CustomViewAbove extends ViewGroup {
39-
private static final String TAG = "CustomViewPager";
39+
private static final String TAG = "CustomViewAbove";
4040
private static final boolean DEBUG = false;
4141

4242
private static final boolean USE_CACHE = false;
@@ -124,7 +124,7 @@ public float getInterpolation(float t) {
124124

125125
private boolean mLastTouchAllowed = false;
126126
private int mSlidingMenuThreshold = 30;
127-
private CustomViewBehind2 mCustomViewBehind2;
127+
private CustomViewBehind mCustomViewBehind;
128128
private boolean mEnabled = true;
129129

130130
private OnPageChangeListener mOnPageChangeListener;
@@ -222,16 +222,19 @@ interface OnAdapterChangeListener {
222222
interface Decor {}
223223

224224
public CustomViewAbove(Context context) {
225-
super(context);
226-
initCustomViewAbove();
225+
this(context, null);
227226
}
228227

229228
public CustomViewAbove(Context context, AttributeSet attrs) {
229+
this(context, attrs, true);
230+
}
231+
232+
public CustomViewAbove(Context context, AttributeSet attrs, boolean isAbove) {
230233
super(context, attrs);
231-
initCustomViewAbove();
234+
initCustomViewAbove(isAbove);
232235
}
233236

234-
void initCustomViewAbove() {
237+
void initCustomViewAbove(boolean isAbove) {
235238
setWillNotDraw(false);
236239
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
237240
setFocusable(true);
@@ -242,9 +245,11 @@ void initCustomViewAbove() {
242245
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
243246
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
244247

245-
View v = new View(getContext());
246-
v.setBackgroundColor(android.R.color.transparent);
247-
setMenu(v);
248+
if (isAbove) {
249+
View v = new View(getContext());
250+
v.setBackgroundColor(android.R.color.transparent);
251+
setMenu(v);
252+
}
248253

249254
final float density = context.getResources().getDisplayMetrics().density;
250255
mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
@@ -504,10 +509,10 @@ public int getChildWidth(int i) {
504509
}
505510

506511
public int getBehindWidth() {
507-
if (mCustomViewBehind2 == null) {
512+
if (mCustomViewBehind == null) {
508513
return 0;
509514
} else {
510-
return mCustomViewBehind2.getWidth();
515+
return mCustomViewBehind.getWidth();
511516
}
512517
}
513518

@@ -766,7 +771,7 @@ protected void setMenu(View v) {
766771
if (mWindow != null) {
767772
removeView((View)mWindow.object);
768773
}
769-
addView(v);
774+
addView(v, 0);
770775
mWindow = ii;
771776
}
772777

@@ -777,12 +782,12 @@ public void setContent(View v) {
777782
if (mContent != null) {
778783
removeView((View)mContent.object);
779784
}
780-
addView(v);
785+
addView(v, 1);
781786
mContent = ii;
782787
}
783788

784-
public void setCustomViewBehind2(CustomViewBehind2 cvb) {
785-
mCustomViewBehind2 = cvb;
789+
public void setCustomViewBehind(CustomViewBehind cvb) {
790+
mCustomViewBehind = cvb;
786791
}
787792

788793
public void addView(View child, int index, ViewGroup.LayoutParams params) {
@@ -966,6 +971,8 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
966971
int childTop = 0;
967972
childLeft = getChildLeft(i);
968973
int childWidth = getChildWidth(i);
974+
Log.v(TAG, "Child#" + i + " left:" + childLeft +
975+
" right:" + (childLeft + child.getMeasuredWidth()));
969976
child.layout(childLeft, childTop,
970977
childLeft + childWidth,
971978
childTop + child.getMeasuredHeight());
@@ -1442,8 +1449,8 @@ public void setScrollScale(float f) {
14421449
@Override
14431450
public void scrollTo(int x, int y) {
14441451
super.scrollTo(x, y);
1445-
if (mCustomViewBehind2 != null && mEnabled) {
1446-
mCustomViewBehind2.scrollTo((int)(x*mScrollScale), y);
1452+
if (mCustomViewBehind != null && mEnabled) {
1453+
mCustomViewBehind.scrollTo((int)(x*mScrollScale), y);
14471454
}
14481455
}
14491456

library/src/com/slidingmenu/lib/CustomViewBehind.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import android.widget.Scroller;
3232

3333
public class CustomViewBehind extends ViewGroup {
34-
private static final String TAG = "CustomViewPager";
34+
private static final String TAG = "CustomViewBehind";
3535
private static final boolean DEBUG = false;
3636

3737
private static final boolean USE_CACHE = false;
@@ -763,6 +763,9 @@ public void setContent(View v) {
763763
ItemInfo ii = new ItemInfo();
764764
ii.position = 0;
765765
ii.object = mAdapter.instantiateItem(this, 0);
766+
if (mContent != null) {
767+
removeView((View)mContent.object);
768+
}
766769
mContent = ii;
767770

768771
mAdapter.notifyDataSetChanged();
@@ -946,24 +949,26 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
946949
ItemInfo ii;
947950
int childLeft = 0;
948951
int childTop = 0;
949-
if (lp.isDecor) {
950-
decorCount++;
951-
childLeft = getChildLeft(i);
952-
int childWidth = child.getMeasuredWidth();
953-
child.layout(childLeft, childTop,
954-
childLeft + child.getMeasuredWidth(),
955-
childTop + child.getMeasuredHeight());
956-
} else if ((ii = infoForChild(child)) != null) {
952+
// if (lp.isDecor) {
953+
// decorCount++;
954+
// childLeft = getChildLeft(i);
955+
// int childWidth = child.getMeasuredWidth();
956+
// child.layout(childLeft, childTop,
957+
// childLeft + child.getMeasuredWidth(),
958+
// childTop + child.getMeasuredHeight());
959+
// } else if ((ii = infoForChild(child)) != null) {
957960
childTop = paddingTop;
958961
if (DEBUG) Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object
959962
+ ":" + childLeft + "," + childTop + " " + child.getMeasuredWidth()
960963
+ "x" + child.getMeasuredHeight());
961964
// TODO PADDING!
962965
childLeft = getChildLeft(i);
966+
Log.v(TAG, "Child#" + i + " left:" + childLeft +
967+
" right:" + (childLeft + child.getMeasuredWidth()));
963968
child.layout(childLeft, childTop,
964969
childLeft + child.getMeasuredWidth(),
965970
childTop + child.getMeasuredHeight());
966-
}
971+
// }
967972
}
968973
}
969974
mTopPageBounds = paddingTop;

library/src/com/slidingmenu/lib/CustomViewBehind2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public class CustomViewBehind2 extends CustomViewAbove {
1111
private static final String TAG = "CustomViewBehind2";
1212

1313
public CustomViewBehind2(Context context) {
14-
super(context);
14+
this(context, null);
1515
}
1616

1717
public CustomViewBehind2(Context context, AttributeSet attrs) {
18-
super(context, attrs);
18+
super(context, attrs, false);
1919
}
2020

2121
public int getDestScrollX() {

library/src/com/slidingmenu/lib/SlidingMenu.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SlidingMenu extends RelativeLayout {
1313
public static final int TOUCHMODE_MARGIN = 1;
1414

1515
private CustomViewAbove mViewAbove;
16-
private CustomViewBehind2 mViewBehind;
16+
private CustomViewBehind mViewBehind;
1717

1818
public SlidingMenu(Context context) {
1919
this(context, null);
@@ -27,13 +27,13 @@ public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
2727
super(context, attrs, defStyle);
2828

2929
LayoutParams behindParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
30-
mViewBehind = new CustomViewBehind2(context);
30+
mViewBehind = new CustomViewBehind(context);
3131
addView(mViewBehind, behindParams);
3232
LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
3333
mViewAbove = new CustomViewAbove(context);
3434
addView(mViewAbove, aboveParams);
35-
// register the CustomViewBehind2 with the CustomViewAbove
36-
mViewAbove.setCustomViewBehind2(mViewBehind);
35+
// register the CustomViewBehind with the CustomViewAbove
36+
mViewAbove.setCustomViewBehind(mViewBehind);
3737

3838
// now style everything!
3939
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu);
@@ -91,13 +91,13 @@ public boolean isSlidingEnabled() {
9191
public void setStatic(boolean b) {
9292
if (b) {
9393
setSlidingEnabled(false);
94-
mViewAbove.setCustomViewBehind2(null);
94+
mViewAbove.setCustomViewBehind(null);
9595
mViewAbove.setCurrentItem(1);
9696
mViewBehind.setCurrentItem(0);
9797
} else {
9898
mViewAbove.setCurrentItem(1);
9999
mViewBehind.setCurrentItem(1);
100-
mViewAbove.setCustomViewBehind2(mViewBehind);
100+
mViewAbove.setCustomViewBehind(mViewBehind);
101101
setSlidingEnabled(true);
102102
}
103103
}

0 commit comments

Comments
 (0)