我想通过 TextView 和 strings.xml 显示多行。我想显示前几行直到页面中间和其他行以显示整个页面。我想显示具有相同宽度页面大小的前几行。
页面左边是图片,页面右边是我的句子。
这是我的代码,但显示的是乱七八糟的。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/logoImage"
android:src="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/txtIntroduce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txtIntroduce"
android:textColor="@color/blue_text"
android:background="@color/blue"/>
</LinearLayout>
字符串.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="intro">................. ....</string>
<resources>
我怎样才能显示这个 View ? 抱歉我的英语不好,感谢您的帮助。
最佳答案
您可以查看 TextView 的这三个 xml 属性:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="end"
android:maxLines="5"
android:singleLine="false" />
在那里您可以定义 TextView 应该有多少行,以及当文本超过 TextView 大小时是否应该显示点(“...”)。
此外,您可以在字符串 .xml 中使用 return 来开始一个新行:("\n")
<string name="intro">This is the first line \n this is a new line.</string>
关于android - 如何让一个TextView有多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18693285/