Android 在recyclerview中将“高度”设置为“包裹内容”时,不会显示图像

Android 在recyclerview中将“高度”设置为“包裹内容”时,不会显示图像,android,android-recyclerview,Android,Android Recyclerview,我想做什么 垂直显示20幅图像。当滚动到最后一个图像时,必须请求接下来的20个图像(分页或无限滚动) 发生了什么事 使用高度设置为包裹内容的recyclerview:没有显示任何图像 使用高度设置为匹配父对象的recylerview:我可以看到图像,但在显示第5幅图像时调用了以下请求。但我想在滚动到最后一张图片时调用它 标题 activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmln

我想做什么

垂直显示20幅图像。当滚动到最后一个图像时,必须请求接下来的20个图像(分页或无限滚动)

发生了什么事

使用高度设置为包裹内容的recyclerview:没有显示任何图像

使用高度设置为匹配父对象的recylerview:我可以看到图像,但在显示第5幅图像时调用了以下请求。但我想在滚动到最后一张图片时调用它

标题 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent"
    android:layout_height="match_parent"
    tools:context="technology.nine.moviedb.MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical">

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

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:id="@+id/progress"
        android:visibility="visible"/>

</RelativeLayout>

对于这个项目

帮我解决这个问题。提前感谢。

item\u movie.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/item_movie">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/image_view"/>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/item_movie">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/image_view"/>

</LinearLayout>
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:id="@+id/image_view"/>


设置布局高度-----50DP、60DP、100DP等.

< P>当你的列表为HythToul时,你应该知道MatCHYPrimor给固定大小的列表,所以它将填充5个项目,并且不考虑更多的空间,考虑使用动态尺寸

的WrAPHY内容。 item_movie.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/item_movie">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/image_view"/>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/item_movie">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/image_view"/>

</LinearLayout>
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:id="@+id/image_view"/>

包裹内容可能会根据高度大小而工作,因此请先检查它

如果你想保持高宽比,你可以使用零高度的重量,安卓将完成这项工作

   <ImageView
    **android:scaleType="centerInside"**
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    />

android:scaleType=“centerInside”


将渲染图像以保持缩放

一切似乎都很好。尝试修改onScrolled函数内的条件,如下所示:

int buffer = 3;//you can modify this accordingly.
if(isScrolling & (scrollOutItem > (totalItems - buffer))){
    //call fetchData();
}

我试着在设置适配器之前调用它。即使图像没有出现@“我认为您需要提供宽度或高度,其中任何一个都应该是固定的。@GaneshMunisifreddy请尝试此
totalItems=movieAdapter.getItemCount()
onScrolled
中,您的API是20项ryt?每次?@Shalu-我希望ImageView的宽度为“匹配父对象”,高度为“包裹内容”。@SantanuSur-我试过了。如果我将recylerView高度设置为
wrap\u content
,则不会显示图像。我想将imageView高度和宽度与纵横比设置为类似。是否设置了布局?宽度将尝试一下。其工作:)但仅当我将recyclerView高度设置为
match\u parent