@@ -158,34 +158,36 @@ public int getItemCount(){
158158 protected View createDefaultTabView (Context context , TabItemSpec tabItem ) {
159159 float density = getResources ().getDisplayMetrics ().density ;
160160
161- LinearLayout ll = new LinearLayout (context );
162- ll .setLayoutParams (new LinearLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .MATCH_PARENT ));
163- ll .setGravity (Gravity .CENTER );
164- ll .setOrientation (LinearLayout .VERTICAL );
165- TypedValue outValue = new TypedValue ();
166- getContext ().getTheme ().resolveAttribute (android .R .attr .selectableItemBackground , outValue , true );
167- ll .setBackgroundResource (outValue .resourceId );
168-
169- ImageView imgView = new ImageView (context );
170- imgView .setScaleType (ScaleType .FIT_CENTER );
171- LinearLayout .LayoutParams imgLP = new LinearLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , this .mMaxImageHeight > 0 ? this .mMaxImageHeight : ViewGroup .LayoutParams .WRAP_CONTENT );
172- imgLP .gravity = Gravity .CENTER ;
173- imgView .setLayoutParams (imgLP );
174-
175- TextView textView = new TextView (context );
176- textView .setGravity (Gravity .CENTER );
177- textView .setMaxWidth ((int ) (ITEM_TEXT_MAX_WIDTH * density ));
178- textView .setTextSize (TypedValue .COMPLEX_UNIT_SP , ITEM_TEXT_SIZE_SP );
179- textView .setTypeface (Typeface .DEFAULT_BOLD );
180- textView .setEllipsize (TextUtils .TruncateAt .END );
181- textView .setMaxLines (1 );
182- textView .setLayoutParams (new LinearLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .WRAP_CONTENT ));
183-
184- this .setupItem (ll , textView , imgView , tabItem );
185-
186- ll .addView (imgView );
187- ll .addView (textView );
188- return ll ;
161+ LinearLayout tabItemLayout = new LinearLayout (context );
162+ tabItemLayout .setLayoutParams (new LinearLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .MATCH_PARENT ));
163+ tabItemLayout .setGravity (Gravity .CENTER );
164+ tabItemLayout .setOrientation (LinearLayout .VERTICAL );
165+ TypedValue backgroundOutValue = new TypedValue ();
166+ getContext ().getTheme ().resolveAttribute (android .R .attr .selectableItemBackground , backgroundOutValue , true );
167+ tabItemLayout .setBackgroundResource (backgroundOutValue .resourceId );
168+
169+ ImageView iconImageView = new ImageView (context );
170+ iconImageView .setScaleType (ScaleType .FIT_CENTER );
171+ int iconImageHeight = this .mMaxImageHeight > 0 ? this .mMaxImageHeight : ViewGroup .LayoutParams .WRAP_CONTENT ;
172+ int iconImageWidth = ViewGroup .LayoutParams .WRAP_CONTENT ;
173+ LinearLayout .LayoutParams iconImageLayoutParams = new LinearLayout .LayoutParams (iconImageWidth , iconImageHeight );
174+ iconImageLayoutParams .gravity = Gravity .CENTER ;
175+ iconImageView .setLayoutParams (iconImageLayoutParams );
176+
177+ TextView titleTextView = new TextView (context );
178+ titleTextView .setGravity (Gravity .CENTER );
179+ titleTextView .setMaxWidth ((int ) (ITEM_TEXT_MAX_WIDTH * density ));
180+ titleTextView .setTextSize (TypedValue .COMPLEX_UNIT_SP , ITEM_TEXT_SIZE_SP );
181+ titleTextView .setTypeface (Typeface .DEFAULT_BOLD );
182+ titleTextView .setEllipsize (TextUtils .TruncateAt .END );
183+ titleTextView .setMaxLines (1 );
184+ titleTextView .setLayoutParams (new LinearLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .WRAP_CONTENT ));
185+
186+ this .setupItem (tabItemLayout , titleTextView , iconImageView , tabItem );
187+
188+ tabItemLayout .addView (iconImageView );
189+ tabItemLayout .addView (titleTextView );
190+ return tabItemLayout ;
189191 }
190192
191193 private void setupItem (LinearLayout ll , TextView textView ,ImageView imgView , TabItemSpec tabItem ){
@@ -241,8 +243,7 @@ public void onSelectedPositionChange(int position, int prevPosition) {
241243 }
242244
243245 private void setImageHeights (){
244- for (int i = 0 ; i < this .mTabItems .length ; i ++) {
245- TabItemSpec tabItem = this .mTabItems [i ];
246+ for (TabItemSpec tabItem : this .mTabItems ) {
246247 if (tabItem .imageHeight == 0 && tabItem .iconId != 0 ) {
247248 Drawable drawable = getResources ().getDrawable (tabItem .iconId );
248249 tabItem .imageHeight = drawable .getIntrinsicHeight ();
0 commit comments