Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int widthSize = MeasureSpec.getSize(widthMeasureSpec);
- int lineWidth = widthSize - getPaddingLeft() - getPaddingRight();
- // Change the text size until the largest line of text fits.
- while (lineWidth < calculateTextWidth()) {
- for (TextView textView : this.childViews) {
- float newSize = textView.getTextSize() - 1;
- textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize);
- }
- }
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
- <com.my.widgets.ScalingTextViewGroup
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:orientation="vertical"
- android:gravity="center_horizontal"
- >
- <TextView
- android:id="@+id/text_1"
- android:text="Text 1"
- android:textSize="20sp" />
- <TextView
- android:id="@+id/text_2"
- android:text="Text 2"
- android:textSize="18sp" />
- <TextView
- android:id="@+id/text_3"
- android:text="Text 3"
- android:textSize="18sp" />
- <TextView
- android:id="@+id/text_4"
- android:text="Text 4"
- android:textSize="18sp" />
- </com.my.widgets.ScalingTextViewGroup>
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int widthMode = MeasureSpec.getMode(widthMeasureSpec);
- if (widthMode != MeasureSpec.UNSPECIFIED) {
- int widthSize = MeasureSpec.getSize(widthMeasureSpec);
- int lineWidth = widthSize - getPaddingLeft() - getPaddingRight();
- // Change the text size until the largest line of text fits.
- while (lineWidth < calculateTextWidth()) {
- for (TextView textView : this.childViews) {
- float newSize = textView.getTextSize() - 1;
- textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize);
- }
- }
- }
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement