有没有人知道在Android中是否可以这样做?
我尝试将描述文本对齐到50p文本的右侧,但它只会写下与50p文本右下角对齐的下一行文本,而不是在其下方包裹。
<TextView
android:id="@+id/product_points_text"
style="@style/TitleTextAppearance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginTop="@dimen/small_margin"
app:layout_constraintTop_toBottomOf="@id/product_image"
tools:text="+40" />
<TextView
android:id="@+id/description_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginTop="@dimen/default_margin"
app:layout_constraintLeft_toRightOf="@id/product_points_text"
app:layout_constraintTop_toBottomOf="@id/product_image"
tools:text="Description of product offer goes here!!!!!" />
答案 0 :(得分:0)
您可以尝试使用SpannableStringBuilder:
SpannableStringBuilder str = new SpannableStringBuilder("some string");
str.setSpan(new AbsoluteSizeSpan(SIZE, true), start, stop, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
将所有内容放在一个TextView中。
编辑:
对于不同的功能,请参阅:
Android: Coloring part of a string using TextView.setText()?
设置样式:
str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, stop, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
等
来源: https://developer.android.com/reference/android/text/style/AbsoluteSizeSpan.html
答案 1 :(得分:0)
试试这个:
<TextView
android:id="@+id/product_points_text"
style="@style/TitleTextAppearance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginTop="@dimen/small_margin"
app:layout_constraintTop_toBottomOf="@id/product_image"
tools:text="+40" />
<TextView
android:id="@+id/description_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_constraintTop_toRightOf="@+id/product_points_text"
android:layout_constraintTop_toEndOf="@+id/product_points_text"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginTop="@dimen/default_margin"
tools:text="Description of product offer goes here!!!!!" />