[英]TextView with multiple lines of text in a wrapping container - wrong height?
我发现以下问题。 像这样简单的东西可以工作:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="long text taking multiple lines ..."/>
</LinearLayout>
但是,如果您在布局中还有另一个组件,则TextView会开始表现异常。 文本超出容器框架似乎很短:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp"
android:text="long text over multiple lines ..."/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bla"/>
</LinearLayout>
为什么会这样呢?
我检查,如果它是某种PADDING
或MARGIN
从LINEAR LAYOUT
还是从TEXTVIEW
本身,貌似不是这样的。
但是我能够通过在TEXTVIEW
上添加android:layout_gravity="center"
来正确对齐它。
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18sp"
android:layout_gravity="center"
android:text="long text over multiple lines ..."/>
除center
以外的某些值也可以使用。
您可以使用
android:singleLine="false"
如果字符串超过
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.