我有一个textView,其中单个文本需要使用两种不同的字体,并且同一文本视图需要具有左右方向的重力。
Java代码
holder.mMessageRowBinding.txtMyRow.setText(messageModel.getMessage()+" "+CommonFragment.convertServerDateToUserTimeZone(messageModel.getUTCTimeZone(),
messageModel.getUTCTimeDate()));
XML代码:
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/layoutThereRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="50dp"
android:background="@drawable/white_corner"
android:orientation="vertical"
android:visibility="@{safeUnbox(!messageThread.fromMe ? View.VISIBLE : View.GONE),default=gone}">
<TextView
android:id="@+id/txtThereHeaderName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingTop="5dp"
android:paddingRight="8dp"
android:textAppearance="?android:textAppearanceSmallInverse"
android:textColor="@color/halfBlackColor"
android:textStyle="bold" />
<TextView
android:id="@+id/txtThereRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="8dp"
android:paddingBottom="5dp"
android:textColor="@color/halfBlackColor"
android:textSize="12sp" />
</androidx.appcompat.widget.LinearLayoutCompat>
当前结果:嗨,这是StackOverflow 12:37 PM
答案 0 :(得分:0)
通过使用SpannableString,您可以实现这一目标
SpannableString string = new SpannableString(messageModel.getMessage()+" "+
CommonFragment.convertServerDateToUserTimeZone(messageModel.getUTCTimeZone(),
messageModel.getUTCTimeDate()));
string.setSpan(new RelativeSizeSpan(1.5f), 10, 24, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);