Skip to content

Commit ba1f987

Browse files
committed
Fix icon position.
1 parent 650279d commit ba1f987

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

app/src/main/java/pl/sigmapoint/StartFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void onClick(View v) {
218218

219219
private void generate() {
220220
generatedCB = new CustomButton(getActivity(),
221-
new ViewGroup.LayoutParams(300, 300),
221+
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200),
222222
bgColorNormalCB.getBackgroundColorNormal(),
223223
txtColorNormalCB.getTextColorNormal(),
224224
null);

app/src/main/res/layout/fragment_generated.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<FrameLayout
1515
android:id="@+id/generated_container"
16-
android:layout_width="wrap_content"
16+
android:layout_width="match_parent"
1717
android:layout_height="wrap_content"
1818
android:layout_centerInParent="true" />
1919

library/src/main/java/pl/sigmapoint/customview/CustomButton.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,18 @@ private void setContent() {
275275
int width = (drawablePosition % 2 == 0) ? 0 : ViewGroup.LayoutParams.MATCH_PARENT;
276276
int height = (drawablePosition % 2 == 0) ? ViewGroup.LayoutParams.MATCH_PARENT : 0;
277277
layoutParamsText = new LinearLayout.LayoutParams(width, height);
278-
layoutParamsImage = new LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
278+
layoutParamsImage = new LayoutParams(width, height);
279279
layoutParamsText.weight = (text != null) ? ((textWeight == 0) ? 1 : textWeight) : 0;
280280
textWeight = (int) layoutParamsText.weight;
281281
if (imageWeight > 0) {
282282
layoutParamsImage = new LinearLayout.LayoutParams(width, height);
283283
layoutParamsImage.weight = imageWeight;
284284
imageWeight = (int) layoutParamsImage.weight;
285+
} else {
286+
if (text == null) {
287+
layoutParamsImage.weight = imageWeight;
288+
imageWeight = (int) layoutParamsImage.weight;
289+
}
285290
}
286291
textView.setLayoutParams(layoutParamsText);
287292
imageContainer.setLayoutParams(layoutParamsImage);
@@ -517,6 +522,12 @@ public void onGlobalLayout() {
517522
else
518523
((LayoutParams) textView.getLayoutParams()).leftMargin = layoutParams.width;
519524
}
525+
if (text == null) {
526+
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
527+
layoutParams.width = 0;
528+
layoutParams.weight = 1;
529+
imageWeight = 1;
530+
}
520531
} else {
521532
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
522533
layoutParams.height = 0;

0 commit comments

Comments
 (0)