我尝试在TextView中添加自定义引号。我用水平创建LinearLayout并添加开始/结束自定义textview。这是我的来源
<LinearLayout
android:id="@+id/description_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/dimen_p_30"
android:layout_marginTop="@dimen/dimen_p_25"
android:layout_marginRight="@dimen/dimen_p_30"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/helvetica_regular"
android:gravity="top"
android:text="“"
android:textColor="#E8E9EF"
android:textSize="@dimen/dimen_p_46" />
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/myriad_geo_medium"
android:gravity="top"
android:maxLines="150"
android:text="test message"
android:textColor="@color/gray"
android:textSize="@dimen/dimen_p_14" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/helvetica_regular"
android:gravity="bottom"
android:text="”"
android:textColor="#E8E9EF"
android:textSize="@dimen/dimen_p_46" />
</LinearLayout>
一切都很完美,但是当我的descriptionTextView
有大文字并且它需要两行时,第3版textview没有显示。是否有任何方法可以解决这个问题或者我的方式是否正确?谢谢
将Exclamations的完整文本添加到一个TextView。使用Spannable字符串将颜色设置为exclamations。
TextView textView = (TextView)findViewById(R.id.mytextview01);
String mText = textView.getText();
Spannable wordtoSpan = new SpannableString(mText);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), (mText.Length()-2), (mText.Length()-1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(wordtoSpan);
像这样使用weight
为你的TextView
s
<LinearLayout
android:id="@+id/description_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/dimen_p_30"
android:layout_marginTop="@dimen/dimen_p_25"
android:layout_marginRight="@dimen/dimen_p_30"
android:orientation="horizontal"
android:weightSum="3"
>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/helvetica_regular"
android:gravity="top"
android:text="“"
android:textColor="#E8E9EF"
android:textSize="@dimen/dimen_p_46" />
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/myriad_geo_medium"
android:gravity="top"
android:maxLines="150"
android:text="test message"
android:textColor="@color/gray"
android:textSize="@dimen/dimen_p_14" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/helvetica_regular"
android:gravity="bottom"
android:text="”"
android:textColor="#E8E9EF"
android:textSize="@dimen/dimen_p_46" />
</LinearLayout>