[英]TextView not wrapping to multiline
I have a TextView
inside a LinearLayout
which displays only a part of its text without wrapping to a newline and cannot understand why. 我在
LinearLayout
内有一个TextView
,它仅显示文本的一部分而不换行,并且无法理解原因。 It doesn't even show the ellipsis somewhere. 它甚至没有在某处显示省略号。
The TextView
TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/import_progress_text"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="end"
style="@style/TxtDefault" />
i also tried layout_weight=0
along with layout_height=0
but still no luck. 我也尝试了
layout_weight=0
和layout_height=0
但还是没有运气。 All the siblings inside the LinearLayout
have layout_height=wrap_content
set. LinearLayout
所有同级都设置了layout_height=wrap_content
。
EDIT 编辑
Okay apparently it works when a fixed width is set, but neither with fill_parent
nor with match_parent
. 显然,当设置了固定宽度时,它可以工作,但是对于
fill_parent
和match_parent
都不能。 Is this the expected behaviour? 这是预期的行为吗?
Per Request the whole layout 根据要求整体布局
Note that inside the FrameLayout is another invisible one, which is rather long 请注意,在FrameLayout内部是另一个不可见的框架,它相当长
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="@style/ContentBody"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/progress"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/import_progress_title"
style="@style/TxtTitle" />
<TextView
android:layout_width="410dp"
android:layout_height="wrap_content"
android:text="@string/import_progress_text"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="end"
style="@style/TxtDefault" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="410dp"
android:layout_height="wrap_content"
android:id="@+id/progress_bar_view"
android:progress="2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/import_progress_start"
android:id="@+id/progress_text_view"
style="@style/TxtSecondary" />
</LinearLayout>
</FrameLayout>
The code snippet is wrapping to multiline perfectly. 该代码段完美地包装为多行。 There might be some problem with the IDE, which is not previewing properly.
IDE可能存在一些问题,无法正确预览。 Test on a real device.
在真实设备上测试。
if you want to always show text in n
lines, just add android:lines="n"
, or if it's not work, try to use for your TextView
-> android:textAppearance="?android:attr/textAppearanceLarge"
如果您想始终以
n
行显示文本,只需添加android:lines="n"
,否则,请尝试将其用于TextView
> android:textAppearance="?android:attr/textAppearanceLarge"
hope that will help. 希望会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.