2016-04-25 54 views
0

我在LinearLayout裏面有一個TextView,它只顯示其文本的一部分而沒有包裝到換行符並且無法理解原因。它甚至不會在某處顯示省略號。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" /> 

我也試圖與layout_height=0但仍沒有運氣一起layout_weight=0LinearLayout內的所有兄弟姐妹都有layout_height=wrap_content集。

EDIT

好當一個固定的寬度被設定顯然它的工作原理,但既不與fill_parent也不與match_parent。這是預期的行爲?

每請求整個佈局
注意,裏面的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> 
+0

請添加完整的佈局xml,謝謝 –

+0

Textview layout_width應該是「wrap_content」 – randy

回答

0

的代碼片段被包裹完美多。 IDE可能會出現某些問題,但無法正常預覽。在真實設備上測試。

+0

哦,我只是意識到預覽看起來很好......只有在設備上它不起作用。 – patman

+0

然後它是一個設備兼容性問題。嘗試使用Android Studio內置仿真器在Galaxy,Nexus等各種設備上進行測試。 – Niladree

0

,如果你想一直顯示文本n行,只需添加android:lines="n", 或者如果它不工作,嘗試使用您的TextView - > android:textAppearance="?android:attr/textAppearanceLarge"

希望會有所幫助。