Android 如何使用TextView进行多行操作
我有一个名为Android 如何使用TextView进行多行操作,android,textview,multiline,Android,Textview,Multiline,我有一个名为main Activity.java的Activity,其中有一个Activity\u main.xml文件。但我不知道如何创建多行文本视图,当我尝试添加第二行时,它会将两行放在同一行的同一空间中 activity_main.xml文本视图 <TextView android:id="@+id/txtView" android:layout_width="fill_parent" android:layout_height="wrap_content"
main Activity.java
的Activity
,其中有一个Activity\u main.xml
文件。但我不知道如何创建多行文本视图,当我尝试添加第二行时,它会将两行放在同一行的同一空间中
activity_main.xml文本视图
<TextView android:id="@+id/txtView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textColorLink="#FFFF00"
android:textStyle="bold"
/
<TextView android:id="@+id/txtView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textStyle="bold"
/>
所以我需要的是有两行,一行表示方向,另一行表示地图视图。试试这个
yourTextView.setText(Html.fromHtml("<div>line1</div> <br /> <div>line2</div>"));
yourTextView.setText(Html.fromHtml(“line1
line2”);
试试这个
yourTextView.setText(Html.fromHtml("<div>line1</div> <br /> <div>line2</div>"));
yourTextView.setText(Html.fromHtml(“line1
line2”);
试试这个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".yourActivity" >
<TextView android:id="@+id/txtView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textColorLink="#FFFF00"
android:textStyle="bold"/>
<TextView android:id="@+id/txtView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtView"
android:text=""
android:textSize="12sp"
android:textStyle="bold"/>
</RelativeLayout>
试试这个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".yourActivity" >
<TextView android:id="@+id/txtView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textColorLink="#FFFF00"
android:textStyle="bold"/>
<TextView android:id="@+id/txtView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtView"
android:text=""
android:textSize="12sp"
android:textStyle="bold"/>
</RelativeLayout>
要添加新行时,请使用此
\n
。像
String str = "Title:\nHere title";
要添加新行时,请使用此
\n
。像
String str = "Title:\nHere title";
使用相对布局并将txtView2显式设置为低于txtView1。 我不会选择HTML解决方案,因为它违背了拥有独立布局文件的目的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout1">
<TextView android:id="@+id/txtView1"
android:text=""
android:textSize="12sp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/txtView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textStyle="bold"
android:layout_below="@id/txtView1"/>
使用相对布局,并将txtView2明确设置为低于txtView1。 我不会选择HTML解决方案,因为它违背了拥有独立布局文件的目的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout1">
<TextView android:id="@+id/txtView1"
android:text=""
android:textSize="12sp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/txtView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textStyle="bold"
android:layout_below="@id/txtView1"/>
您需要在strings.xml文件中定义文本。是的,您也可以在其中定义格式化的html 因此,您可以尝试以下方法:
<string name="nice_html">
<![CDATA[Don't worry we will never share this with anyone<br/>
By Clicking register you are indicating that you have read and agreed to the <br/>
<u>Terms of services</u> and <u>Privacy Policy</u>
]]></string>
这是最干净的方法。Inshallah。您需要在strings.xml文件中定义文本。是的,您也可以在其中定义格式化的html 因此,您可以尝试以下方法:
<string name="nice_html">
<![CDATA[Don't worry we will never share this with anyone<br/>
By Clicking register you are indicating that you have read and agreed to the <br/>
<u>Terms of services</u> and <u>Privacy Policy</u>
]]></string>
这是最干净的方法。Inshallah。您可以在xml文件的textview中添加android:maxLines=“5”属性
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:maxLines="5"
android:textAppearance="?android:attr/textAppearanceLarge" />
就这样您可以在xml文件的textview中添加android:maxLines=“5”属性
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:maxLines="5"
android:textAppearance="?android:attr/textAppearanceLarge" />
就这样为什么不在清单xml中创建两个不同的
TextView
?只需将TextView
的宽度指定为wrap\u content
,然后再试一次。等着瞧吧。我的错。没有完全读取xml。但是,您使用的是RelativeLayout
,还是什么?尝试使用一个RelativeLayout
,然后将它们放在彼此的上面/下面?发布完整的xml。另外,可能是复制/粘贴错误,但您在第一个TextView
中缺少“>”,为什么不在清单xml中创建两个不同的TextView
?只需将TextView
的宽度指定为wrap\u content
,然后再试一次。等等,看看您是怎么做的。我的错。没有完全读取xml。但是,您使用的是RelativeLayout
,还是什么?尝试使用一个RelativeLayout
,然后将它们放在彼此的上面/下面?发布完整的xml。此外,可能是复制/粘贴错误,但您的第一个文本视图中缺少“>”
,
标记中的某些信息可能是特定于您的应用程序的。你一定要看,怎么会这样?或者你能更深入一点吗?顺便说一句,我真的很感激你的回答,它很快而且切中要害。很高兴我能帮上忙。直到现在才注意到您的其他评论,tools:context
和xmnls
标记可能需要修改才能用于您的目的。
标记中的某些信息可能特定于您的应用程序。你一定要看,怎么会这样?或者你能更深入一点吗?顺便说一句,我真的很感激你的回答,它很快而且切中要害。很高兴我能帮上忙。直到现在才注意到您的其他评论,tools:context
和xmnls
标记可能需要修改才能用于您的目的。文本视图中的HTML代码可以执行多行操作。。。英雄联盟你会用大炮杀苍蝇吗?这是一种杀苍蝇的方法!如果你有更好的想法,就写下你的答案!这不是一个你可以拿答案开玩笑的地方!我同意塔拉哈科森的观点。尝试使用TextView中的nice.HTML代码来执行多行操作。。。英雄联盟你会用大炮杀苍蝇吗?这是一种杀苍蝇的方法!如果你有更好的想法,就写下你的答案!这不是一个你可以拿答案开玩笑的地方!我同意塔拉哈科森的观点。试着表现得好一点。抱歉,尼尔,我在这之前看到了TronicZomb的回应,但我真的很感激你的回应。抱歉,尼尔,我在这之前看到了TronicZomb的回应,但我真的很感激你的回应。嗯,这是两年前回答的。嗯,这是两年前回答的。