24
24
import android .view .FocusFinder ;
25
25
import android .view .Gravity ;
26
26
import android .view .KeyEvent ;
27
+ import android .view .LayoutInflater ;
27
28
import android .view .MotionEvent ;
28
29
import android .view .SoundEffectConstants ;
29
30
import android .view .VelocityTracker ;
33
34
import android .view .ViewParent ;
34
35
import android .view .accessibility .AccessibilityEvent ;
35
36
import android .view .animation .Interpolator ;
37
+ import android .widget .ImageView ;
38
+ import android .widget .LinearLayout ;
36
39
import android .widget .Scroller ;
37
40
38
41
public class CustomViewAbove extends ViewGroup {
@@ -124,7 +127,7 @@ public float getInterpolation(float t) {
124
127
125
128
private boolean mLastTouchAllowed = false ;
126
129
private int mSlidingMenuThreshold = 30 ;
127
- private CustomViewBehind mCustomViewBehind ;
130
+ private CustomViewBehind2 mCustomViewBehind2 ;
128
131
private boolean mEnabled = true ;
129
132
130
133
private OnPageChangeListener mOnPageChangeListener ;
@@ -246,8 +249,10 @@ void initCustomViewAbove(boolean isAbove) {
246
249
mMaximumVelocity = configuration .getScaledMaximumFlingVelocity ();
247
250
248
251
if (isAbove ) {
249
- View v = new View (getContext ());
250
- v .setBackgroundColor (android .R .color .transparent );
252
+ View v = new LinearLayout (getContext ());
253
+ v .setBackgroundResource (android .R .color .transparent );
254
+ // ImageView v = new ImageView(getContext());
255
+ // v.setImageResource(R.drawable.ic_launcher);
251
256
setMenu (v );
252
257
}
253
258
@@ -509,10 +514,10 @@ public int getChildWidth(int i) {
509
514
}
510
515
511
516
public int getBehindWidth () {
512
- if (mCustomViewBehind == null ) {
517
+ if (mCustomViewBehind2 == null ) {
513
518
return 0 ;
514
519
} else {
515
- return mCustomViewBehind .getWidth ();
520
+ return mCustomViewBehind2 .getWidth ();
516
521
}
517
522
}
518
523
@@ -771,7 +776,7 @@ protected void setMenu(View v) {
771
776
if (mWindow != null ) {
772
777
removeView ((View )mWindow .object );
773
778
}
774
- addView (v , 0 );
779
+ addView (v );
775
780
mWindow = ii ;
776
781
}
777
782
@@ -782,12 +787,12 @@ public void setContent(View v) {
782
787
if (mContent != null ) {
783
788
removeView ((View )mContent .object );
784
789
}
785
- addView (v , 1 );
790
+ addView (v );
786
791
mContent = ii ;
787
792
}
788
793
789
- public void setCustomViewBehind ( CustomViewBehind cvb ) {
790
- mCustomViewBehind = cvb ;
794
+ public void setCustomViewBehind2 ( CustomViewBehind2 cvb ) {
795
+ mCustomViewBehind2 = cvb ;
791
796
}
792
797
793
798
public void addView (View child , int index , ViewGroup .LayoutParams params ) {
@@ -816,9 +821,9 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) {
816
821
}
817
822
818
823
ItemInfo infoForChild (View child ) {
819
- if (child .equals (mWindow .object )) {
824
+ if (mWindow != null && child .equals (mWindow .object )) {
820
825
return mWindow ;
821
- } else if (child .equals (mContent .object )) {
826
+ } else if (mContent != null && child .equals (mContent .object )) {
822
827
return mContent ;
823
828
}
824
829
return null ;
@@ -880,7 +885,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
880
885
} else if (consumeHorizontal ) {
881
886
heightMode = MeasureSpec .EXACTLY ;
882
887
}
883
-
888
+ int pos = infoForChild (child ).position ;
889
+ childWidthSize = getChildWidth (pos );
884
890
final int widthSpec = MeasureSpec .makeMeasureSpec (childWidthSize , widthMode );
885
891
final int heightSpec = MeasureSpec .makeMeasureSpec (childHeightSize , heightMode );
886
892
child .measure (widthSpec , heightSpec );
@@ -966,11 +972,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
966
972
final View child = getChildAt (i );
967
973
if (child .getVisibility () != GONE ) {
968
974
final LayoutParams lp = (LayoutParams ) child .getLayoutParams ();
969
- ItemInfo ii ;
975
+ int pos = infoForChild ( child ). position ;
970
976
int childLeft = 0 ;
971
977
int childTop = 0 ;
972
- childLeft = getChildLeft (i );
973
- int childWidth = getChildWidth (i );
978
+ childLeft = getChildLeft (pos );
979
+ int childWidth = getChildWidth (pos );
974
980
Log .v (TAG , "Child#" + i + " left:" + childLeft +
975
981
" right:" + (childLeft + child .getMeasuredWidth ()));
976
982
child .layout (childLeft , childTop ,
@@ -1449,8 +1455,8 @@ public void setScrollScale(float f) {
1449
1455
@ Override
1450
1456
public void scrollTo (int x , int y ) {
1451
1457
super .scrollTo (x , y );
1452
- if (mCustomViewBehind != null && mEnabled ) {
1453
- mCustomViewBehind .scrollTo ((int )(x *mScrollScale ), y );
1458
+ if (mCustomViewBehind2 != null && mEnabled ) {
1459
+ mCustomViewBehind2 .scrollTo ((int )(x *mScrollScale ), y );
1454
1460
}
1455
1461
}
1456
1462
0 commit comments