SegmentedButton icon indicating copy to clipboard operation
SegmentedButton copied to clipboard

Can't center two lines text

Open cristidregan opened this issue 5 years ago • 5 comments

When having 2 lines text on SegmentedButton it is aligned left. Is there any way to center it? image

cristidregan avatar Jun 10 '20 13:06 cristidregan

Great question. I'm not sure off the top of my head, but can you give me some sample code so I can play around with it a bit?

addisonElliott avatar Jun 10 '20 14:06 addisonElliott

@addisonElliott Sure: <com.addisonelliott.segmentedbutton.SegmentedButtonGroup android:id="@+id/participantsSG" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:background="@color/white" app:borderColor="@color/light_grey" app:borderWidth="1dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/participantsTV" app:position="0" app:radius="9dp" app:ripple="false" app:selectedBackground="@color/light_blue" app:selectedBorderColor="@color/blue" app:selectedBorderWidth="1dp" app:selectedButtonRadius="8dp">

            <com.addisonelliott.segmentedbutton.SegmentedButton
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_marginStart="1.5dp"
                android:layout_marginTop="1.5dp"
                android:layout_marginBottom="1.5dp"
                android:layout_weight="1"
                android:fontFamily="@font/roboto_condensed_bold"
                app:selectedTextColor="@color/blue"
                app:text="Alone"
                app:textColor="@color/dark"
                app:textSize="@dimen/small_text_size" />

            <com.addisonelliott.segmentedbutton.SegmentedButton
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_gravity="center"
                android:layout_marginTop="1.5dp"
                android:layout_marginBottom="1.5dp"
                android:layout_weight="1"
                android:fontFamily="@font/roboto_condensed_bold"
                app:selectedTextColor="@color/blue"
                app:text="Household member(s)"
                app:textColor="@color/dark"
                app:textSize="@dimen/small_text_size" />

            <com.addisonelliott.segmentedbutton.SegmentedButton
                android:layout_width="0dp"
                android:layout_height="@dimen/button_height"
                android:layout_marginTop="1.5dp"
                android:layout_marginEnd="1.5dp"
                android:layout_marginBottom="1.5dp"
                android:layout_weight="1"
                android:fontFamily="@font/roboto_condensed_bold"
                app:selectedTextColor="@color/blue"
                app:text="Friend(s)"
                app:textColor="@color/dark"
                app:textSize="@dimen/small_text_size" />
        </com.addisonelliott.segmentedbutton.SegmentedButtonGroup>

cristidregan avatar Jun 10 '20 15:06 cristidregan

@addisonElliott any updates?

cristidregan avatar Jun 18 '20 12:06 cristidregan

Sorry no, I've been busy lately. Unfortunately if you need a fix right this moment, it's probably better to hack something together or do something else as I don't know when I'll be able to commit time to this.

PRs are always welcome if you find out the issue.

addisonElliott avatar Jun 18 '20 13:06 addisonElliott

@cristidregan Just change Layout.Alignment.ALIGN_NORMAL To Layout.Alignment.ALIGN_CENTER in File SegmentedButton.java

Example for your reference :

if (VERSION.SDK_INT >= VERSION_CODES.M) { textStaticLayout = StaticLayout.Builder .obtain(text, 0, text.length(), textPaint, textWidth) .setAlignment(Layout.Alignment.ALIGN_CENTER) .build(); } else { textStaticLayout = new StaticLayout(text, textPaint, textWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0, false); }

GovindaPaliwal avatar Nov 19 '20 07:11 GovindaPaliwal