Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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
Java Android:让TextView宽度与水平循环视图中的ImageView匹配_Java_Android_Android Recyclerview - Fatal编程技术网

Java Android:让TextView宽度与水平循环视图中的ImageView匹配

Java Android:让TextView宽度与水平循环视图中的ImageView匹配,java,android,android-recyclerview,Java,Android,Android Recyclerview,我有一个水平回收视图,其中包含一个图像和下面的标题。我需要的recyclerview显示所有的图像与相同的分隔和下面的文字。如果文本超过图像的宽度,则应将其换行或剪切。然而,在我目前的设置中,长文本在图像之间造成了巨大的间隙,因为它们保持在一行中 这是recycler视图项的xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http:

我有一个水平回收视图,其中包含一个图像和下面的标题。我需要的recyclerview显示所有的图像与相同的分隔和下面的文字。如果文本超过图像的宽度,则应将其换行或剪切。然而,在我目前的设置中,长文本在图像之间造成了巨大的间隙,因为它们保持在一行中

这是recycler视图项的xml:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<androidx.cardview.widget.CardView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    app:cardElevation="0dp">


        <FrameLayout
            android:id="@+id/media_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            <ImageView
                android:id="@+id/topimage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:cropToPadding="true"
                android:paddingStart="8dp"
                android:paddingEnd="8dp"
                android:scaleType="fitXY" />



        <TextView
            android:id="@+id/title"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/topImage"
            android:padding="2dp"
            android:text="@string/placeholder_name"
            android:textColor="@android:color/black"
            android:textSize="16sp"
            android:layout_marginTop="5dp"/>

        <TextView
            android:id="@+id/subtitle"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/title"
            android:padding="2dp"
            android:text="@string/placeholder_details"
            android:textColor="@android:color/black"
            android:textSize="15sp"
            android:layout_marginBottom="10dp" />

            </RelativeLayout>
        </FrameLayout>


</androidx.cardview.widget.CardView>


</LinearLayout>
如何更改此设置,使recycler view item成为图像的宽度,并使文本在图像下换行


PS:我正在使用Java。

您可以使用

android: singleline = "false"


然后使用“最大行数”属性设置允许的最大行数。

谢谢,但即使添加了此项,recyclerView项也是全文的宽度,而不是图像的宽度。我需要它是图像的宽度,并有文字包装,如果需要。我可以看到你使用的是一个相对布局。使用约束布局可以使您的生活更轻松。如果我是你,在文本视图中,尝试使用“布局”\u constraintEnd\u toEndOf=“yourImageViewIdHere”和“布局”\u constraintStart\u toStartOf=“yourImageViewIdHere”。(更改为约束布局后)可以在此处检查如何使用它:
android: singleline = "false"