2016-08-30 240 views
0

我有一個ListView,但列表中的某些文本項超出了單詞換行的寬度限制。通常這很好;然而,我想在ListView中顯示儘可能多的行,所以有辦法剪輯或限制到某個字符長度並將省略號放在末尾Android Studio ListView,限制行的長度

例如: 這是一條很長的路線文本將環繞

這個 這是一個很長的線...

我已經看到了一些XML線一個TextView

android:ellipsize="end" 
android:singleLine="true" 

該工程爲TetView但沒有看到anythi納克一個ListView做到這一點(沒有嘗試使用這些XML選項,但它沒有工作)

我發現最近被以下

android:maxLines="1" 
android:ellipsize="end" 

,沒有工作,除非它是在一個錯誤Android Studio或者模擬器?

我使用的是Windows 10機器

Android Studio 2.1.3 
Build #AI-143.3101438 
jdk1.8.0_91 

最新更新版本謝謝

編輯 XML代碼的活動

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.example.danield.notes.MainActivity" 
    tools:showIn="@layout/activity_main" 
    android:padding="0dp"> 

    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/listView" 
     android:maxLines="1" 
     android:ellipsize="end" 
     android:textFilterEnabled="false" 
     android:layout_centerInParent="true" 
     android:layout_alignParentTop="false" 
     android:layout_alignParentLeft="false" /> 

</RelativeLayout> 
+0

你在你的列表中的項目使用的是什麼樣的佈局?你也可以提供更多的代碼。 – thekevshow

+0

相對佈局 –

+0

嘗試將其更改爲線性佈局或框架佈局。你的列表項目本身沒有自己的佈局,或者它沒有? – thekevshow

回答

0

你試過乾淨rebulid該項目 ?

+0

是沒有影響:( –

+0

您可以複製並粘貼完整的XML嗎? –

+0

當然,編輯:) –

0

請參考此鏈接Android custom Row Item for ListView

爲您創建一個自定義佈局ListView項和這些PARAMS添加到您的TextView:

android:maxLines="1" 
android:ellipsize="end" 

希望這有助於:)