我在思考如何让一个
TextView
显示在多行上,而不需要在 XML 中硬编码宽度。 <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Long multiline text"/>
<TextView
android:textColor="@color/text_color"
android:layout_width="130dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
希望听到任何想法。
编辑:我的问题是,当文本超出设置的宽度(因为它达到屏幕的末端)时,一部分文本就不会显示。我希望文本能够分成两行显示。
android:text="长文本\n多行\n文本"
。你也可以使用maxWidth
属性将TextView包裹在内容周围,直到达到所需的宽度。 - SamTextView
的默认行为不就是这样吗?如果你移除maxLines
和singleLine
会发生什么呢? - nhaarmanTextView
吗? - nhaarman