Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't center two lines text #33

Open
cristidregan opened this issue Jun 10, 2020 · 5 comments
Open

Can't center two lines text #33

cristidregan opened this issue Jun 10, 2020 · 5 comments

Comments

@cristidregan
Copy link

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

@addisonElliott
Copy link
Owner

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?

@cristidregan
Copy link
Author

@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
Copy link
Author

@addisonElliott any updates?

@addisonElliott
Copy link
Owner

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.

@GovindaPaliwal
Copy link

@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); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants