Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ConstraintLayout子文本视图截断文本_Android_Textview_Android Constraintlayout - Fatal编程技术网

Android ConstraintLayout子文本视图截断文本

Android ConstraintLayout子文本视图截断文本,android,textview,android-constraintlayout,Android,Textview,Android Constraintlayout,我使用ConstraintLayout布局RecyclerView的单元格,元素TextView(id:cell\u summary)切断其长文本 以下是单元格布局xml代码: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

我使用
ConstraintLayout
布局
RecyclerView
的单元格,元素
TextView
(id:cell\u summary)切断其长文本

以下是单元格布局xml代码:

<?xml version="1.0" encoding="utf-8"?>    
<android.support.constraint.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

  <TextView
    android:id="@+id/cell_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="16dp"
    android:maxLines="2"
    android:text="And we find ourselves cruelly cut off from the wireless world"
    android:textColor="@android:color/black"
    android:textSize="16sp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

  <ImageView
    android:id="@+id/cell_thumb"
    android:layout_width="120dp"
    android:layout_height="88dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="8dp"
    android:background="#cccccc"
    android:scaleType="centerCrop"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@id/cell_title" />

  <TextView
    android:id="@+id/cell_datetime"
    android:layout_width="0dp"
    android:layout_height="15dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="16dp"
    android:text="2Hours"
    android:textColor="#999999"
    android:textSize="12sp"
    app:layout_constraintBottom_toBottomOf="@id/cell_thumb"
    app:layout_constraintLeft_toRightOf="@id/cell_thumb"
    app:layout_constraintRight_toRightOf="parent" />

  <TextView
    android:id="@+id/cell_summary"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="12dp"
    android:text="But then we were not being singled out, the entire country lives in a bubble of unreality, cut off from the outside world and watched by an army of informers."
    android:ellipsize="end"
    app:layout_constraintBottom_toTopOf="@id/cell_datetime"
    app:layout_constraintLeft_toLeftOf="@id/cell_datetime"
    app:layout_constraintRight_toRightOf="@id/cell_datetime"
    app:layout_constraintTop_toTopOf="@id/cell_thumb" />

  <View
    android:layout_width="0dp"
    android:layout_height="0.5dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="16dp"
    android:background="#dddddd"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/cell_thumb" />

</android.support.constraint.ConstraintLayout>


如果添加
android:maxLines=“3”
,则
文本视图将正常工作。但是这里我需要一个无限的
文本视图

试试下面的代码这会帮你解决问题:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:orientation="vertical">

<TextView
    android:id="@+id/cell_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="2"
    android:text="And we find ourselves cruelly cut off from the wireless world"
    android:textColor="@android:color/black"
    android:textSize="16sp" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/cell_thumb"
        android:layout_width="120dp"
        android:layout_height="88dp"
        android:layout_gravity="center_vertical"
        android:background="#cccccc"
        android:scaleType="centerCrop" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/cell_summary"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:text="But then we were not being singled out, the entire country lives in a bubble of unreality, cut off from the outside world and watched by an army of informers." />

        <TextView
            android:id="@+id/cell_datetime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="2Hours"
            android:textColor="#999999"
            android:textSize="12sp" />
    </LinearLayout>
</LinearLayout>


<View
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="#dddddd" />


从单元格摘要中删除android:layout\u marginBottom=“12dp”
,您期望得到什么?要用“…”或什么来省略号?@pskink是的,我添加了android:ellipsize=“end”,但不起作用您想要实现什么?@RamiJemli截断长文本并以“…”结束