0

I'm currently working on a calculator android app, and I want to keep all user expressions on a single line. To do this, I need to be able to decrease the textsize of the texview as more and more input is added (so the text would never have to overflow to the second line). Any ideas on how to achieve this? If I'm not explaining the problem well enough, Google's Calculator does this. If this is an extremely difficult task, I can always resort to a horizontal scroll view.

4rsenal
  • 41
  • 7
  • 2
    Possible duplicate of [Auto Scale TextView Text to Fit within Bounds](http://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds) – royB Mar 12 '17 at 17:59

2 Answers2

0

There are ways you can do this on your own, but seems like an ideal use case for: android-autofittextview

Sample usage:

<me.grantland.widget.AutofitTextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:maxLines="2"
    android:textSize="40sp"
    autofit:minTextSize="16sp"
    />
Veneet Reddy
  • 2,164
  • 1
  • 19
  • 34
0

Validate the length and reduce/increase the Size of that text

Example

//You can also use Textview/EditText
TextView.addTextChangedListener(new TextWatcher() {

@Override
public void afterTextChanged(Editable s) {}

@Override    
public void beforeTextChanged(CharSequence s, int start,
 int count, int after) {
}

@Override    
public void onTextChanged(CharSequence s, int start,
 int before, int count) {
  if(s.length() <5)
    TextView.setTextSize(TypedValue.COMPLEX_UNIT_SP,context.getResources().getDimension(R.dimen.text_medium));
  else
   EditTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP,context.getResources().getDimension(R.dimen.large));
 //Here I included the Textsize from Dimens file 
 }
});

dimens.xml

<resources>
<dimen name="text_medium">12sp</dimen>
<dimen name="large">25sp</dimen>
</resources>
sivaprakash
  • 429
  • 5
  • 14