android - 如何让一个TextView有多行?

标签 android android-layout user-interface textview

我想通过 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/

相关文章:

android - 如何在蜂窝模拟器中给出最大大小的 vm 堆和 ram 大小和分区

python - 如何为视频播放器选择文件

python - 如何从其父级(另一个 wx.panel 对象)中删除或销毁 wx.panel?

android - 如何防止ViewFlipper循环

java - 每次 Activity 恢复时,自定义 ListView 都会重复自身(android)

android - 类似于 CloudKit 的多平台 MBaaS?

android - 淡入淡出动画闪烁 - Android

java - 将 Inflate 布局设置为更小

Android:TextInputLayout 总是从顶部留出一些空间

java - 为什么我的 Java gui 会调整标签大小?