2
2
3
3
import android .content .Context ;
4
4
import android .content .res .TypedArray ;
5
- import android .os .Handler ;
6
5
import android .support .annotation .NonNull ;
7
6
import android .text .TextUtils ;
8
7
import android .util .AttributeSet ;
11
10
import android .view .Gravity ;
12
11
import android .view .View ;
13
12
import android .view .ViewGroup ;
14
- import android .view .animation .Animation ;
15
- import android .view .animation .AnimationUtils ;
16
13
import android .widget .FrameLayout ;
17
14
import android .widget .LinearLayout ;
18
15
import android .widget .TextView ;
@@ -38,9 +35,6 @@ public class DropDownMenu extends LinearLayout {
38
35
//tabMenuView里面选中的tab位置,-1表示未选中
39
36
private int current_tab_position = -1 ;
40
37
41
- //分别是菜单进入,弹出,遮罩View进入,弹出动画
42
- private Animation dropdown_in , dropdown_out , dropdown_mask_in , dropdown_mask_out ;
43
-
44
38
//分割线颜色
45
39
private int dividerColor = 0xffcccccc ;
46
40
//tab选中颜色
@@ -57,10 +51,6 @@ public class DropDownMenu extends LinearLayout {
57
51
//tab未选中图标
58
52
private int menuUnselectedIcon = R .mipmap .drop_down_unselected_icon ;
59
53
60
- private boolean hasAnimation = true ;
61
-
62
- private boolean tabClickable = false ;
63
-
64
54
65
55
public DropDownMenu (Context context ) {
66
56
super (context , null );
@@ -109,12 +99,6 @@ public DropDownMenu(Context context, AttributeSet attrs, int defStyleAttr) {
109
99
containerView .setLayoutParams (new FrameLayout .LayoutParams (FrameLayout .LayoutParams .MATCH_PARENT , FrameLayout .LayoutParams .MATCH_PARENT ));
110
100
addView (containerView , 2 );
111
101
112
- //初始化动画
113
- dropdown_in = AnimationUtils .loadAnimation (context , R .anim .dropdown_in );
114
- dropdown_out = AnimationUtils .loadAnimation (context , R .anim .dropdown_out );
115
- dropdown_mask_in = AnimationUtils .loadAnimation (context , R .anim .dropdown_mask_in );
116
- dropdown_mask_out = AnimationUtils .loadAnimation (context , R .anim .dropdown_mask_out );
117
-
118
102
}
119
103
120
104
/**
@@ -170,17 +154,7 @@ private void addTab(@NonNull List<String> tabTexts, int i) {
170
154
tab .setOnClickListener (new OnClickListener () {
171
155
@ Override
172
156
public void onClick (View v ) {
173
- tabClickable = false ;
174
- setTabClickable (tabClickable );
175
157
switchMenu (tab );
176
- new Handler ().postDelayed (new Runnable () {
177
- @ Override
178
- public void run () {
179
- tabClickable = true ;
180
- setTabClickable (tabClickable );
181
- }
182
- },200 );
183
-
184
158
}
185
159
});
186
160
tabMenuView .addView (tab );
@@ -202,8 +176,8 @@ public void setTabText(String text) {
202
176
((TextView ) tabMenuView .getChildAt (current_tab_position )).setText (text );
203
177
}
204
178
205
- public void setTabClickable (boolean clickable ){
206
- for (int i = 0 ; i < tabMenuView .getChildCount (); i = i + 2 ) {
179
+ public void setTabClickable (boolean clickable ) {
180
+ for (int i = 0 ; i < tabMenuView .getChildCount (); i = i + 2 ) {
207
181
tabMenuView .getChildAt (i ).setClickable (clickable );
208
182
}
209
183
}
@@ -215,31 +189,8 @@ public void closeMenu() {
215
189
((TextView ) tabMenuView .getChildAt (current_tab_position )).setTextColor (textUnselectedColor );
216
190
((TextView ) tabMenuView .getChildAt (current_tab_position )).setCompoundDrawablesWithIntrinsicBounds (null , null ,
217
191
getResources ().getDrawable (menuUnselectedIcon ), null );
218
- if (hasAnimation ) {
219
- popupMenuViews .getChildAt (current_tab_position / 2 + 1 ).startAnimation (dropdown_out );
220
- } else {
221
- popupMenuViews .setVisibility (View .GONE );
222
- }
192
+ popupMenuViews .setVisibility (View .GONE );
223
193
current_tab_position = -1 ;
224
- if (hasAnimation )
225
- maskView .startAnimation (dropdown_mask_out );
226
-
227
- dropdown_out .setAnimationListener (new Animation .AnimationListener () {
228
- @ Override
229
- public void onAnimationStart (Animation animation ) {
230
-
231
- }
232
-
233
- @ Override
234
- public void onAnimationEnd (Animation animation ) {
235
- popupMenuViews .setVisibility (View .GONE );
236
- }
237
-
238
- @ Override
239
- public void onAnimationRepeat (Animation animation ) {
240
-
241
- }
242
- });
243
194
244
195
}
245
196
@@ -266,11 +217,7 @@ private void switchMenu(View target) {
266
217
} else {
267
218
if (current_tab_position == -1 ) {
268
219
popupMenuViews .setVisibility (View .VISIBLE );
269
- if (hasAnimation )
270
- maskView .startAnimation (dropdown_mask_in );
271
220
popupMenuViews .getChildAt (i / 2 + 1 ).setVisibility (View .VISIBLE );
272
- if (hasAnimation )
273
- popupMenuViews .getChildAt (i / 2 + 1 ).startAnimation (dropdown_in );
274
221
} else {
275
222
popupMenuViews .getChildAt (i / 2 + 1 ).setVisibility (View .VISIBLE );
276
223
}
0 commit comments