Open cristidregan opened 4 years ago
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 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>
@addisonElliott any updates?
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.
@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); }
When having 2 lines text on SegmentedButton it is aligned left. Is there any way to center it?