3

enter image description here

enter image description here

enter image description here

Update: I just used setTextScaleX instead of setScalex to scale the textView and it worked as what I expected this time.

Just like the photos above. I use ConstraintLayout to keep the space between "$" and center textView and "00". When I set 5555 to the center textView, it became wider, but I want to keep its original size. So I scaled the "5555" part, I found the constraints did not update as well. Can anybody give me some advice? Thanks a lot!

My layout xml is as following.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.echo.tipcalculator.fragments.FeeUnitFragment">

    <TextView
        android:id="@+id/fee_title"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:text="title"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginStart="16dp" />

    <TextView
        android:id="@+id/fee_unit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="$"
        android:textSize="20dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/fee_title"
        app:layout_constraintLeft_toLeftOf="@+id/fee_title" />

    <TextView
        android:id="@+id/fee_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:clickable="true"
        android:ellipsize="end"
        android:gravity="top"
        android:includeFontPadding="false"
        android:maxLines="1"
        android:text="0"
        android:textSize="80dp"
        app:layout_constraintLeft_toRightOf="@+id/fee_unit"
        app:layout_constraintTop_toTopOf="@+id/fee_unit" />

    <TextView
        android:id="@+id/fee_decimal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="00"
        android:textSize="20dp"
        app:layout_constraintTop_toTopOf="@+id/fee_main"
        app:layout_constraintLeft_toRightOf="@+id/fee_main"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp" />

</android.support.constraint.ConstraintLayout>
echo
  • 1,244
  • 1
  • 16
  • 40
  • 1
    Can you post your xml so we can play with it? – themichaelscott May 16 '17 at 15:46
  • Just updated my post. Thank you. – echo May 16 '17 at 15:54
  • Thanks for the xml, I see it looking like the top example you posted. What do you mean when you say you're trying to scale it? What is it you change that makes the 55 get thinner? – themichaelscott May 16 '17 at 16:04
  • Updated my post again. Hope you can understand my problems now. Thanks again! – echo May 16 '17 at 16:14
  • 2
    Are you trying to scale the text size within the bounds of the existing text field? (As the numbers get larger, the height and width of each number becomes smaller to allow the entire number to fit in the field) If that's the case, there are some other posts about this: http://stackoverflow.com/questions/2617266/how-to-adjust-text-font-size-to-fit-textview Also, there's a github project that's not a library, but the author encourages you to copy and paste his custom text view into your own project: https://github.com/erchenger/SizeAdjustingTextView/blob/master/SizeAdjustingTextView.java – themichaelscott May 16 '17 at 16:28
  • 1
    Thanks for your help! I used setTextScaleX and solved my problem! – echo May 16 '17 at 18:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144399/discussion-between-themichaelscott-and-echo). – themichaelscott May 16 '17 at 22:17

0 Answers0