1
1
package com .sothree .slidinguppanel .demo ;
2
2
3
+ import com .nineoldandroids .view .animation .AnimatorProxy ;
3
4
import com .sothree .slidinguppanel .SlidingUpPanelLayout ;
4
5
import com .sothree .slidinguppanel .SlidingUpPanelLayout .PanelSlideListener ;
5
-
6
6
import android .net .Uri ;
7
+ import android .os .Build ;
7
8
import android .os .Bundle ;
9
+ import android .annotation .SuppressLint ;
8
10
import android .app .Activity ;
9
11
import android .content .Intent ;
10
12
import android .text .Html ;
11
13
import android .text .method .LinkMovementMethod ;
12
14
import android .util .Log ;
15
+ import android .util .TypedValue ;
13
16
import android .view .Menu ;
14
17
import android .view .View ;
18
+ import android .view .ViewGroup ;
15
19
import android .view .View .OnClickListener ;
16
20
import android .view .Window ;
17
21
import android .widget .Button ;
@@ -28,20 +32,21 @@ protected void onCreate(Bundle savedInstanceState) {
28
32
getWindow ().requestFeature (Window .FEATURE_ACTION_BAR_OVERLAY );
29
33
setContentView (R .layout .activity_demo );
30
34
31
- SlidingUpPanelLayout layout = (SlidingUpPanelLayout ) findViewById (R .id .sliding_layout );
35
+ final SlidingUpPanelLayout layout = (SlidingUpPanelLayout ) findViewById (R .id .sliding_layout );
32
36
layout .setPanelSlideListener (new PanelSlideListener () {
33
37
@ Override
34
38
public void onPanelSlide (View panel , float slideOffset ) {
35
39
Log .i (TAG , "onPanelSlide, offset " + slideOffset );
36
- if (slideOffset < 0.2 ) {
37
- if (getActionBar ().isShowing ()) {
38
- getActionBar ().hide ();
39
- }
40
- } else {
41
- if (!getActionBar ().isShowing ()) {
42
- getActionBar ().show ();
43
- }
44
- }
40
+ setActionBarTranslation (layout .getCurrentParalaxOffset ());
41
+ // if (slideOffset < 0.2) {
42
+ // if (getActionBar().isShowing()) {
43
+ // getActionBar().hide();
44
+ // }
45
+ // } else {
46
+ // if (!getActionBar().isShowing()) {
47
+ // getActionBar().show();
48
+ // }
49
+ // }
45
50
}
46
51
47
52
@ Override
@@ -108,4 +113,31 @@ public boolean onCreateOptionsMenu(Menu menu) {
108
113
return true ;
109
114
}
110
115
116
+ @ SuppressLint ("NewApi" )
117
+ public void setActionBarTranslation (float y ) {
118
+ // Figure out the actionbar height
119
+ int actionBarHeight = 0 ;
120
+ TypedValue tv = new TypedValue ();
121
+ if (getTheme ().resolveAttribute (android .R .attr .actionBarSize , tv , true )) {
122
+ actionBarHeight = TypedValue .complexToDimensionPixelSize (tv .data ,getResources ().getDisplayMetrics ());
123
+ }
124
+ // A hack to add the translation to the action bar
125
+ ViewGroup content = ((ViewGroup ) findViewById (android .R .id .content ).getParent ());
126
+ int children = content .getChildCount ();
127
+ for (int i = 0 ; i < children ; i ++) {
128
+ View child = content .getChildAt (i );
129
+ if (child .getId () != android .R .id .content ) {
130
+ if (y <= -actionBarHeight ) {
131
+ child .setVisibility (View .GONE );
132
+ } else {
133
+ child .setVisibility (View .VISIBLE );
134
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB ) {
135
+ child .setTranslationY (y );
136
+ } else {
137
+ AnimatorProxy .wrap (child ).setTranslationY (y );
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
111
143
}
0 commit comments