In a LinearLayout, I am trying to display an integer number using images for digits. I want the number to be centered and the images to scale depending on how many digits are present.
My initial layout with 2 digits:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<view
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="center"
>
<ImageView
app:srcCompat="@drawable/ic_digit_0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_weight="1"
/>
<ImageView
app:srcCompat="@drawable/ic_digit_0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_weight="1"
/>
</LinearLayout>
And here is what it looks like.
A) With 4 digits, everything looks good, the digits fit horizontally and are as tall as possible vertically.
B) With many more digits, it still scales nicely to the available space.
C) But when the LinearLayout height is reduced, the 4 digits separate and gaps appear between them.
D) By removing the layout_weight from each ImageView, the 4 digits come back together.
E) But when the LinearLayout height is increased, the digits scale to the full height of the view and some vanish horizontally off screen.
How can I have these digit images resize to fill the available space, show all digits and be centered without gaps, while retaining their scale proportions, regardless of the LinearLayout dimensions?
Thanks.