Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
交错网格视图在android中无法正常工作_Android_Staggered Gridview_Staggeredgridlayout_Staggeredgridlayoutmanager - Fatal编程技术网

交错网格视图在android中无法正常工作

交错网格视图在android中无法正常工作,android,staggered-gridview,staggeredgridlayout,staggeredgridlayoutmanager,Android,Staggered Gridview,Staggeredgridlayout,Staggeredgridlayoutmanager,我使用交错网格视图,它位于NestedScrollview中。我不知道在第一次加载时(如果图像缓存不存在的话),它是一个比另一个低。交错网格视图有什么问题吗?或者是因为我的布局,它是这样来的。任何人都请帮忙 我的布局xml如下所示 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schema

我使用交错网格视图,它位于NestedScrollview中。我不知道在第一次加载时(如果图像缓存不存在的话),它是一个比另一个低。交错网格视图有什么问题吗?或者是因为我的布局,它是这样来的。任何人都请帮忙

我的布局xml如下所示

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:expandedTitleTextAppearance="@android:color/transparent">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleTextAppearance="@android:color/transparent">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                android:maxHeight="@dimen/detail_backdrop_maxheight"
                android:adjustViewBounds="true"
                app:layout_collapseMode="parallax"
                android:contentDescription="Top Image"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin"
                app:expandedTitleTextAppearance="@android:color/transparent"/>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <com.hit.pretstreet.pretstreet.core.customview.TextViewPret
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/yellow"
            style="@style/textview_normal"
            android:id="@+id/tv_heading_photos"
            app:pret_typeface="@string/font_redvelvet_regular"/>

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/rv_images"
            android:layout_marginLeft="-2dp"
            android:layout_marginRight="-2dp"
            android:nestedScrollingEnabled="false"/>

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

注意:我正在从服务器加载图像


我终于得到了答案。这是因为我在加载图像时丢失了占位符

recycler_item.xml


你可以发布一些代码吗?在你使用gridview&layoutmanager的地方,etcI已经更新了我的问题。请看一看。
<?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="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@color/cardview_dark_background"
    tools:context=".MainActivity">

    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardPreventCornerOverlap="false"
        android:theme="@style/Theme.MaterialComponents.DayNight"
        app:cardBackgroundColor="@color/cardview_shadow_start_color"
        app:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <com.google.android.material.imageview.ShapeableImageView
                android:id="@+id/ivTemplateThumbnail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                android:adjustViewBounds="true"
                android:src="@mipmap/ic_launcher" />
                
            <TextView
                android:id="@+id/tvTemplateName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center_horizontal"
                android:fontFamily="sans-serif-black"
                android:text="Poster Maker"
                android:textSize="@dimen/_16ssp" />
        </LinearLayout>

    </com.google.android.material.card.MaterialCardView>


</LinearLayout>
   <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rvStaggered"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layoutManager="androidx.recyclerview.widget.StaggeredGridLayoutManager"
                app:spanCount="2"
                android:orientation="vertical"
                tools:itemCount="5"
                tools:listitem="@layout/item_staggered_main" />
  @Override
public void onBindViewHolder(@NonNull TemplateListAdapter.TemplateListItemViewHolder holder, int position) {

    Glide.with(mContext)
            .load(listTemplateData.get(position).getTemplateUrl()).placeholder(R.drawable.placeholdertemplate)
            .into(holder.ivTemplateThumbnail);
    holder.tvTemplateName.setText(listTemplateData.get(position).getTemplateName());

    holder.ivTemplateThumbnail.setOnClickListener(view -> {templateItemClick.onTemplateItemClick(position);});


}