GridLayoutManager错误显示图像

时间:2017-01-25 12:01:34

标签: android android-recyclerview universal-image-loader gridlayoutmanager

我有不同数量的图像(从1到8)。图片显示在prenotazioni GridLayoutManager

UniversalImageLoader

适配器中的GridLayoutManager(Xamarin Android / C#),但它类似于Android / Java):

        <android.support.v7.widget.RecyclerView
            android:id="@+id/sharedGridLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            local:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_below="@id/expandTextView" />

的xml:

 GridLayoutManager layoutManager = null;
                        if (item.UserImages.Count == 1)
                        {
                            layoutManager = new GridLayoutManager(_activityContext, 1);
                        }
                        if (item.UserImages.Count == 2)
                        {
                            layoutManager = new GridLayoutManager(_activityContext, 2);
                        }
                        else if (item.UserImages.Count == 3)
                        {
                            layoutManager = new GridLayoutManager(_activityContext, 3);
                        }
                        else if (item.UserImages.Count == 4)
                        {
                            layoutManager = new GridLayoutManager(_activityContext, 2);
                        }
                        else if (item.UserImages.Count == 5)
                        {
                            layoutManager = new GridLayoutManager(_activityContext, 4);
                            layoutManager.SetSpanSizeLookup(new MySpanSizeLookup(5));
                        }
                        else if (item.UserImages.Count == 6)
                        {
                            layoutManager = new GridLayoutManager(_activityContext, 3);
                        }
                        else if (item.UserImages.Count == 7)
                        {
                            layoutManager = new GridLayoutManager(_activityContext, 3);
                            layoutManager.SetSpanSizeLookup(new MySpanSizeLookup(7));
                        }
                        else if (item.UserImages.Count == 8)
                        {
                            layoutManager = new GridLayoutManager(_activityContext, 4);
                        }
                        vh.RecyclerGridView.NestedScrollingEnabled = false;
                        vh.RecyclerGridView.SetLayoutManager(layoutManager);
                        var photoImageAdapter = new PhotoListItemAdapter(_imageLoader, vh.RecyclerGridView, item.UserImages, _activityContext);
                        vh.RecyclerGridView.SetAdapter(photoImageAdapter);

当我快速滚动GridLayoutManager的高度显示错误时:

enter image description here

如何解决?

我尝试重新绘制recyclerview,但它没有帮助:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:descendantFocusability="blocksDescendants"
    android:layout_marginBottom="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/relativeLayout1"
    android:background="@color/white"
    android:fadeScrollbars="false">
    <android.support.v7.widget.CardView
        local:cardUseCompatPadding="true"
        local:cardPreventCornerOverlap="false"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        local:cardElevation="0dp"
        local:cardMaxElevation="0dp">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/main_post_block"
            android:layout_marginTop="10sp">
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/linearLayout5">
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="13dp"
                    android:id="@+id/linearLayout2">
                    <ImageView
                        android:src="@drawable/person_image_empty"
                        android:layout_width="50px"
                        android:layout_height="50px"
                        android:id="@+id/postAva" />
                </LinearLayout>
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/header_post_layout"
                    android:layout_marginLeft="3dp">
                    <LinearLayout
                        android:orientation="vertical"
                        android:minWidth="50px"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/desc">
                        <TextView
                            android:text="@string/medium_text"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:id="@+id/UserName"
                            android:textColor="@color/primaryDark" />
                        <TextView
                            android:text="@string/date_time_post"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:id="@+id/dateText" />
                    </LinearLayout>
                    <ImageButton
                        android:src="@drawable/popup_menu"
                        android:background="?android:attr/selectableItemBackground"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:id="@+id/popupMenuButton"
                        android:layout_alignParentRight="true" />
                </RelativeLayout>
            </LinearLayout>
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_marginTop="10dp"
                android:id="@+id/relative_layout_with_main_text"
                android:layout_height="wrap_content">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/postText"
                    android:minHeight="20dp"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="13dp"
                    android:layout_marginRight="13dp" />
                <TextView
                    android:id="@+id/expandTextView"
                    android:text="@string/expand_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/postText"
                    android:layout_marginLeft="13dp"
                    android:layout_marginRight="13dp" />
                    <android.support.v7.widget.RecyclerView
                    android:id="@+id/sharedGridLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    local:layout_behavior="@string/appbar_scrolling_view_behavior"
                    android:layout_below="@id/expandTextView" />
            </RelativeLayout>
          </LinearLayout>
    </android.support.v7.widget.CardView>
</RelativeLayout>

0 个答案:

没有答案