Align Top Two Textviews With Different Font Sizes
Im using constraint layout and i want to achieve the following: The app:layout_constraintBaseline_toBaselineOf attribute bottom aligns the two textviews, is there any way to top a
Solution 1:
So it seems there is no a convenient way of doing this and a custom view must be implemented. I've taken inspiration from here:
Solution 2:
Try this .
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:id="@+id/tv_unit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="6dp"android:text="$"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintTop_toTopOf="parent"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="top"android:text="120"android:textSize="40sp"android:textStyle="bold"app:layout_constraintLeft_toRightOf="@+id/tv_unit"app:layout_constraintTop_toTopOf="parent"/></android.support.constraint.ConstraintLayout>
Like this .
Solution 3:
Do this way
Strings="$<sub>12 </sub>";
textView.setText(Html.fromHtml(s)); // 12 will cropped // solution:
s = "$<sub>12 </sub>\t "; // add behind ending of sup tag the tabulator \t,// but not char \t but only press to TAB key!!! in source code
textView.setText(Html.fromHtml(s)); // 12 is visible correctly
http://android.okhelp.cz/whittled-superscript-sup-tag-textview-android-issue/
Solution 4:
try this you can use Html.fromHtml for this purpose
Html.fromHtml Returns displayable styled text from the provided HTML string.
yourTextview.setText(Html.fromHtml("<sup><small>$</small></sup>42"));
or try this use SpannableString
TextViewtextView= rootView.findViewById(R.id.tv);
SpannableStringBuildersb=newSpannableStringBuilder("$42");
sb.setSpan(newSuperscriptSpan(), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(sb, TextView.BufferType.SPANNABLE);
Post a Comment for "Align Top Two Textviews With Different Font Sizes"