简体   繁体   中英

Android TextView Text Auto fit

I have found a solution to fit text inside a TextView at Auto Scale TextView Text to Fit within Bounds . However, my solution doesn't seem to work.

Here is my xml:

<parkpurdue.parkpurdue.AutoResizeTextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"

    android:text="Park @ Purdue"
    android:layout_weight="1.6"
    android:background="#3366FF"
    android:id="@+id/parkAtPurdue"
    android:singleLine="true"
    android:gravity="center"
    android:textColor="#FFFFFF"
    android:maxLines="1"/>

And here is my java code:

TextView topText = (TextView) findViewById(R.id.parkAtPurdue);
topText.setText("Park at Purdue");

I tried changing the java code to this as well:

AutoResizeTextView topText = new AutoResizeTextView(getApplicationContext());
topText = (AutoResizeTextView) findViewById(R.id.parkAtPurdue);
topText.setText("Park at Purdue");

I tried calling the topText.resize() function as well. No apparent results were found. What am I doing wrong? What do I need to change?

Try:

AutoResizeTextView topText = (AutoResizeTextView) findViewById(R.id.parkAtPurdue);
topText.setText("Park at Purdue");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM