@@ -53,6 +53,8 @@ public class CustomButton extends LinearLayout implements View.OnClickListener {
53
53
private int imagePadding ;
54
54
private int [] imagePaddingArray ;
55
55
private int imageScaleTypeAttr ;
56
+ private int imageWeight ;
57
+ private int textWeight ;
56
58
57
59
private int shapeType ; // converted shape type from shapeTypeAttr
58
60
private ImageView .ScaleType imageScaleType ;
@@ -83,6 +85,7 @@ public CustomButton(Context context, AttributeSet attrs) {
83
85
textPaddingArray [TOP ] = (int ) attributes .getDimension (R .styleable .CustomButton_cb_text_padding_top , textPadding );
84
86
textPaddingArray [RIGHT ] = (int ) attributes .getDimension (R .styleable .CustomButton_cb_text_padding_right , textPadding );
85
87
textPaddingArray [BOTTOM ] = (int ) attributes .getDimension (R .styleable .CustomButton_cb_text_padding_bottom , textPadding );
88
+ textWeight = attributes .getInteger (R .styleable .CustomButton_cb_text_weight , 1 );
86
89
87
90
shapeRadius = attributes .getDimension (R .styleable .CustomButton_cb_shape_radius , 0 );
88
91
shapeTypeAttr = attributes .getInt (R .styleable .CustomButton_cb_shape_type , 0 );
@@ -99,12 +102,13 @@ public CustomButton(Context context, AttributeSet attrs) {
99
102
drawableNormal = attributes .getDrawable (R .styleable .CustomButton_cb_image_normal );
100
103
drawablePressed = attributes .getDrawable (R .styleable .CustomButton_cb_image_pressed );
101
104
drawableDisabled = attributes .getDrawable (R .styleable .CustomButton_cb_image_disabled );
102
- imageScaleTypeAttr = attributes .getInteger (R .styleable .CustomButton_cb_image_scale_type , 0 );
105
+ imageScaleTypeAttr = attributes .getInteger (R .styleable .CustomButton_cb_image_scale_type , 3 );
103
106
imagePadding = (int ) attributes .getDimension (R .styleable .CustomButton_cb_image_padding , 0 );
104
107
imagePaddingArray [LEFT ] = (int ) attributes .getDimension (R .styleable .CustomButton_cb_image_padding_left , imagePadding );
105
108
imagePaddingArray [TOP ] = (int ) attributes .getDimension (R .styleable .CustomButton_cb_image_padding_top , imagePadding );
106
109
imagePaddingArray [RIGHT ] = (int ) attributes .getDimension (R .styleable .CustomButton_cb_image_padding_right , imagePadding );
107
110
imagePaddingArray [BOTTOM ] = (int ) attributes .getDimension (R .styleable .CustomButton_cb_image_padding_bottom , imagePadding );
111
+ imageWeight = attributes .getInteger (R .styleable .CustomButton_cb_image_weight , 1 );
108
112
109
113
if (backgroundColorState != null ) { // if backgroundColor state is not null the set color from color state list to specific colors
110
114
backgroundColorStateListToIntegers (backgroundColorState );
@@ -166,17 +170,27 @@ public void setEnabled(boolean enabled) {
166
170
167
171
private void setContent (Context context ) {
168
172
removeAllViews ();
173
+ textView = null ;
174
+ imageContainer = null ;
169
175
170
176
LinearLayout .LayoutParams layoutParams = new LinearLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT );
171
- textView = new TextView (context );
172
- setTextPadding (textPaddingArray );
173
177
container = new LinearLayout (context );
174
178
container .setLayoutParams (layoutParams );
175
179
container .setOrientation (VERTICAL );
176
- layoutParams .weight = 1 ;
180
+
181
+ textView = new TextView (context );
182
+ imageContainer = new ImageView (context );
183
+ setTextPadding (textPaddingArray );
184
+
185
+ LayoutParams layoutParamsText = new LinearLayout .LayoutParams (0 , ViewGroup .LayoutParams .MATCH_PARENT );
186
+ LayoutParams layoutParamsImage = new LinearLayout .LayoutParams (0 , ViewGroup .LayoutParams .MATCH_PARENT );
187
+ layoutParamsText .weight = textWeight ;
188
+ layoutParamsImage .weight = imageWeight ;
189
+
190
+ textView .setLayoutParams (layoutParamsText );
191
+ imageContainer .setLayoutParams (layoutParamsImage );
177
192
178
193
if (drawablePosition < 0 && drawablePosition > 4 ) {
179
- textView .setLayoutParams (layoutParams );
180
194
textView .setGravity (Gravity .CENTER );
181
195
container .addView (textView );
182
196
} else {
@@ -185,10 +199,8 @@ private void setContent(Context context) {
185
199
listDrawable .addState (new int []{android .R .attr .state_enabled }, drawableNormal );
186
200
listDrawable .addState (new int []{}, drawableDisabled );
187
201
188
- imageContainer = new ImageView (context );
189
202
imageContainer .setPadding (imagePaddingArray [LEFT ], imagePaddingArray [TOP ], imagePaddingArray [RIGHT ], imagePaddingArray [BOTTOM ]);
190
203
imageContainer .setScaleType (imageScaleType );
191
- imageContainer .setLayoutParams (layoutParams );
192
204
if (drawable != null ) {
193
205
imageContainer .setImageDrawable (drawable );
194
206
} else {
@@ -205,7 +217,6 @@ private void setContent(Context context) {
205
217
break ;
206
218
}
207
219
if (text != null ) {
208
- textView .setLayoutParams (layoutParams );
209
220
textView .setGravity (Gravity .CENTER );
210
221
container .addView (textView );
211
222
}
0 commit comments