как сделать Android kotiln RecyclerView textview динамической высотой

#android #kotlin

#Android #kotlin

Вопрос:

я хочу динамический RecyclerView, но мой RecyclerView не является динамическим, если закончено более 3 строк букв, изображение невидимо и обрезано, поэтому я хочу динамический элемент RecyclerView.

это мой код элемента recyclerview

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal">

<ImageView
    android:id="@ id/linear_imageView"
    android:layout_width="54dp"
    android:layout_height="54dp"
    tools:srcCompat="@tools:sample/avatars" />

<LinearLayout
    android:layout_gravity="center_vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@ id/linear_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:layout_gravity="center_vertical"/>

    <TextView
        android:id="@ id/linear_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</LinearLayout>
  

Ответ №1:

установите атрибут высоты wrap_content в контейнере корневого представления

Ответ №2:

Из обновления библиотеки поддержки Android 23.2.1 все WRAP_CONTENT должны работать правильно.

Пожалуйста, обновите версию библиотеки в файле gradle ИЛИ для дальнейшего :

 compile 'com.android.support:recyclerview-v7:23.2.1'