Last active
January 4, 2016 19:09
-
-
Save ayushhgoyal/8665833 to your computer and use it in GitHub Desktop.
These files can be used to implement shrinkable textviews in android projects, textview will change its textSize according to the length of data being set in textview. Values are supposed to be played with.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShrinkableTextView extends TextView { | |
public ShrinkableTextView(Context context) { | |
super(context); | |
} | |
public ShrinkableTextView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
public ShrinkableTextView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override | |
public void setText(CharSequence text, BufferType type) { | |
super.setText(text, type); | |
if (text.length() < 7) { | |
this.setTextSize(20f); | |
} else if (text.length() > 7 && text.length() < 10) { | |
this.setTextSize(15f); | |
} else if (text.length() >= 10) { | |
this.setTextSize(12f); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment