I have faced following issue when using textview with autoresize
Following is my layout xml to do auto size
Above code is working fine and did auto complete resize.
but For ex,
if I set value 100
then after some calculation or button click I want to change value to 10000 then text size is too small even if we have space to show this big value.
To solve above problem need to do following.
Following is my layout xml to do auto size
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvAmount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollHorizontally="true"
android:maxWidth="@dimen/_290sdp"
android:maxHeight="@dimen/_50sdp"
android:gravity="start|bottom"
android:textSize="@dimen/_28ssp"
android:maxLines="1"
android:textColor="@color/charcoal"
android:includeFontPadding="false"
android:layout_toStartOf="@+id/tvCurrency"
tools:text="200"
app:autoSizeTextType="uniform"
app:autoSizeMinTextSize="@dimen/_5ssp"
app:autoSizeMaxTextSize="@dimen/_25ssp"
app:autoSizeStepGranularity="1sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tvCurrency" />
Above code is working fine and did auto complete resize.
but For ex,
if I set value 100
then after some calculation or button click I want to change value to 10000 then text size is too small even if we have space to show this big value.
To solve above problem need to do following.
tvAmount.setHorizontallyScrolling(true) tvAmount.text = value?.getDecimalFormat() tvAmount.setHorizontallyScrolling(false)
I have to enable and disable horizontal scrolling because internally for autosize text calculation, if horizontal scrolling is true text view's available drawing width is "1024 * 1024" and after setting text, we should disable horizontal scroll so text
size may decrease if required.
No comments :
Post a Comment