在recycleview上的wrap_content,取项目的高度(水平列表)

Max*_*nck 6 android android-layout android-recyclerview

我有一个RecycleView,设置为水平.现在我希望高度与视图中项目的高度相匹配.我事先并不知道高度.

目前我有这个:

主要片段:

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

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="horizontal"
        android:layout_marginLeft="1dp"
        android:layout_marginRight="1dp"
        android:layout_marginTop="1dp"
        android:layout_gravity="top"
        android:id="@+id/my_listview"/>

</RelativeLayout>


<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />
Run Code Online (Sandbox Code Playgroud)

图片

<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/banner_image"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:background="@color/dark_gray"
    />
Run Code Online (Sandbox Code Playgroud)

但它总是占用整个屏幕.所以我之间有很多空白.有没有办法可以在recycleview项目上使用wrap_content?

这是它目前的样子: 在此输入图像描述

我目前放置了2个横幅,顶部有大空白,小图像是带有recyclerview的横幅.下面的图片只是放在图像视图中的图像(它应该是什么样子,但我希望它带有recyclerview,所以如果我有多个,我可以滚动横幅)

Ric*_*ard 0

您可能错误地膨胀了布局。

你用过吗?

layoutInflater.inflate(R.layout.your_layout, null);
Run Code Online (Sandbox Code Playgroud)

尝试使用替代。(另一种方式会影响测量)

layoutInflater.inflate(R.layout.your_layout, parent, false);
Run Code Online (Sandbox Code Playgroud)