Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – How to respect view size inside RecyclerView item

Posted on November 14, 2022

Solution 1 :

Well You are forcing each item to take require width by using android:layout_width="wrap_content" in each View. If you can fix the width of your ImageView then by using android:maxWidth="XXdp" in Text view you can achieve what you want.

Code will be as follows –

<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
    android_layout_height="wrap_content">

    <ImageView
        android_id="@+id/cast_image"
        android_layout_width="100dp"                 //here fixing width to 100dp
        android_layout_height="wrap_content"
        android_layout_marginStart="8dp"
        android_scaleType="centerCrop"
        app_layout_constraintEnd_toEndOf="parent"
        app_layout_constraintStart_toStartOf="parent"
        app_layout_constraintTop_toTopOf="parent"
        tools_srcCompat="@tools:sample/avatars" />

    <TextView
        android_id="@+id/cast_name_text"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_maxWidth="100dp"                      //fixing TextView to max 100dp
        android_layout_marginTop="8dp"
        android_text="TextView"
        app_layout_constraintEnd_toEndOf="@+id/cast_image"
        app_layout_constraintStart_toStartOf="@+id/cast_image"
        app_layout_constraintTop_toBottomOf="@+id/cast_image" />

    <TextView
        android_id="@+id/cast_char_text"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_marginTop="8dp"
        android_text="TextView"
        app_layout_constraintEnd_toEndOf="@+id/cast_name_text"
        app_layout_constraintStart_toStartOf="@+id/cast_name_text"
        app_layout_constraintTop_toBottomOf="@+id/cast_name_text" />
</androidx.constraintlayout.widget.ConstraintLayout>

Following xml will result as –

enter image description here

Happy Coding !

Problem :

I have RecyclerView item with one image and two text views.

If the text is too long, it is causing that one item will be bigger then other item, and overall a bad UI.

What can I do to limit the text to respect the width of another view – the image in that case?(The “three dots” will be proper solution for me)

my layout code for recycler view item:

<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
    android_layout_height="wrap_content">

    <ImageView
        android_id="@+id/cast_image"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_marginStart="8dp"
        android_scaleType="centerCrop"
        app_layout_constraintEnd_toEndOf="parent"
        app_layout_constraintStart_toStartOf="parent"
        app_layout_constraintTop_toTopOf="parent"
        tools_srcCompat="@tools:sample/avatars" />

    <TextView
        android_id="@+id/cast_name_text"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_marginTop="8dp"
        android_text="TextView"
        app_layout_constraintEnd_toEndOf="@+id/cast_image"
        app_layout_constraintStart_toStartOf="@+id/cast_image"
        app_layout_constraintTop_toBottomOf="@+id/cast_image" />

    <TextView
        android_id="@+id/cast_char_text"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_marginTop="8dp"
        android_text="TextView"
        app_layout_constraintEnd_toEndOf="@+id/cast_name_text"
        app_layout_constraintStart_toStartOf="@+id/cast_name_text"
        app_layout_constraintTop_toBottomOf="@+id/cast_name_text" />
</androidx.constraintlayout.widget.ConstraintLayout>

Image for clarifying the problem –

id

READ  [ANSWERED] android espresso - In mockk, can every be called twice on the same method
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress