1

I have checked this answer and this answer but still could not figure out why my ellipsize still doesn't work.

I use the following CardView inside a RecyclerView.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 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:id="@+id/cardview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginVertical="2dp"
    app:cardCornerRadius="4dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="8dp">

        <android.support.v7.widget.CardView
            android:id="@+id/food_image_card"
            android:layout_width="80dp"
            android:layout_height="80dp">

            <ImageView
                android:id="@+id/food_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                app:srcCompat="@drawable/food_image_place_holder" />

        </android.support.v7.widget.CardView>

        <LinearLayout
            android:id="@+id/food_info"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/food_name_row"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toEndOf="@id/food_image_card"
                app:layout_constraintTop_toTopOf="@+id/food_image_card">

                <TextView
                    android:id="@+id/food_name"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:text="Food Name"
                    android:textSize="18sp"
                    android:textStyle="bold" />

                <ImageView
                    android:id="@+id/liked_image"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_marginHorizontal="4dp"
                    android:padding="4dp"
                    app:srcCompat="@drawable/ic_undo_like" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tag_row"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginVertical="2dp">
                <TextView
                    android:id="@+id/tag_header"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/tag_header" />

                <TextView
                    android:id="@+id/tag_content"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:maxLines="1"
                    android:ellipsize="end"
                    android:text="Placeholder" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/note_row"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginVertical="2dp">

                <TextView
                    android:id="@+id/note_header"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/note_header" />

                <TextView
                    android:id="@+id/note_content"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:maxLines="3"
                    android:text="Placeholder" />
            </LinearLayout>

        </LinearLayout>

    </LinearLayout>
</android.support.v7.widget.CardView>

Although tag_content and note_content look ellipsized in Android Studio (1st image), they actually don't ellipsize on my cell phone (first item on 2nd image). Any ideas why?

I think there is nothing wrong with the xml. The reason why it does not ellipsize is I changed the text in my adapter.

This is my project website and the posted code is here and will be used in this adapter

Android StudioMy Cell Phone

Seaky Lone
  • 992
  • 1
  • 10
  • 29

1 Answers1

0

You have force TextView note_content to have 3 lines, so it will not ellipsized if content can be fit in 3 lines.

 <TextView
          android:id="@+id/note_content"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ellipsize="start"
          android:maxLines="3"
          android:text="Placeholder" />

If you change android:maxLines="1" text will be ellipsized.

Nikhil Sharma
  • 897
  • 1
  • 4
  • 18