Android TextView排列(放置在上一个TextView的最后一行末尾)
有两个背景颜色不同的Android TextView排列(放置在上一个TextView的最后一行末尾),android,textview,Android,Textview,有两个背景颜色不同的Textview,第二个Textview必须放在第一个Textview的最后一行的末尾。我需要在哪里以及如何安排第二个textview 试试看 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView and
Textview
,第二个Textview
必须放在第一个Textview的最后一行的末尾。我需要在哪里以及如何安排第二个textview
试试看
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
通常,我们使用HTML文本来获取此信息。
我们可以为不同的文本使用任意多的文本样式。通过这种方式,您可以为每个文本设置不同的属性
例如:
在上面,您可以独立定义文本属性。最后,将此文本放在Textview中。因此,我们可以使用单个TextView本身来实现这一点
例如:
String str = "<a>This is a <font color='#800000FF'> blue text</font> and this is a <font color='red'> red text</font> </a>";
TextView textView = (TextView)findViewById(R.id.text);
textView.setText(Html.fromHtml(str, Html.FROM_HTML_MODE_COMPACT));
String str=“这是一个蓝色文本,这是一个红色文本”;
TextView TextView=(TextView)findViewById(R.id.text);
setText(Html.fromHtml(str,Html.FROM_Html_MODE_COMPACT));
显示您希望如何排列它们的图像。添加了图像使用1个文本视图和2个可设置字符串(它们是可设置样式的,您可以为它们设置不同的颜色,等等)
String str = "<a>This is a <font color='#800000FF'> blue text</font> and this is a <font color='red'> red text</font> </a>";
TextView textView = (TextView)findViewById(R.id.text);
textView.setText(Html.fromHtml(str, Html.FROM_HTML_MODE_COMPACT));