滑动刷新布局会破坏回收器项目模板

时间:2016-11-16 12:04:24

标签: c# mvvm xamarin xamarin.android mvvmcross

Hi MvvmCross / Xamarin Devs,

我遇到了一个围绕MvxRecyclerView和android.support.v4.widget.SwipeRefreshLayout的问题。 Android上使用以下方法会出现此问题:

  • Xamarin版本:7.0.1.3(Xamarin Business)
  • SDK工具版本:25.1.7
  • SDK平台工具版本:24.0.1
  • SDK Build Tools版本:23.0.3
  • MvvmCross V4.3.0。

所以这就是发生的事情。我有一个MvxRecyclerView绑定到一个可观察的集合,并有一个自定义模板。当我们点击列表的底部时,我也使用TemplateSelector来显示“加载单元格”。 MvxRecyclerList包含在android.support.v4.widget.SwipeRefreshLayout中,以实现滑动刷新模式。

当结果加载到列表中时,它显示为应该,导航回来并返回列表也是如此。单元格模板布局看起来完全一样。如下所示。

enter image description here

但是,当我进行刷新以及我正在等待的数据最终返回时,布局是“破碎”,一切都在那里,但它已经搞砸了。见下文

enter image description here

好像这并不奇怪,每当你进行刷新时,被破坏的单元就会交换掉。

enter image description here

有时没有一个被打破。最后要补充的是,细胞在被回收后会修复它们。

我已经把它缩小到MvxRecyclerView包含在SwipeRefreshLayout中的事实,没有那个我可以多次调用重载函数,而不会出现一次单元格错误。

非常感谢任何帮助或指示。

更新:ItemTemplate Xml

<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff">
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="100dp">
    <Mvx.MvxImageView
        android:id="@+id/car_item_template_image_view"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="10dp"
        android:scaleType="centerCrop"
        android:background="@drawable/image_placeholder"
        local:MvxBind="ImageUrl MainImageUrl" />
    <RelativeLayout
        android:orientation="vertical"
        android:background="@color/white"
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:layout_marginLeft="10dp"
        android:layout_gravity="center_vertical">
        <TextView
            android:id="@+id/car_item_template_make_text"
            android:text="Make"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:textColor="@color/theme_blue"
            android:fontFamily="sans-serif-light"
            android:textSize="@dimen/car_item_template_title_text_size"
            local:MvxBind="Text Make, Converter=EmptyStringCheck"
            android:ellipsize="end"
            android:singleLine="true" />
        <TextView
            android:text="Model"
            android:layout_width="@dimen/car_item_template_model_text_width"
            android:layout_height="25dp"
            android:layout_marginLeft="7dp"
            android:textColor="@color/theme_blue"
            android:layout_toRightOf="@id/car_item_template_make_text"
            android:layout_toLeftOf="@+id/car_item_template_price_text"
            android:fontFamily="sans-serif-light"
            android:textSize="@dimen/car_item_template_title_text_size"
            local:MvxBind="Text Model, Converter=EmptyStringCheck"
            android:ellipsize="end"
            android:singleLine="true" />
        <TextView
            android:id="@+id/car_item_template_price_text"
            android:text="Price"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/car_item_template_make_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:textColor="@color/theme_blue"
            android:fontFamily="sans-serif-light"
            android:textSize="@dimen/car_item_template_title_text_size"
            local:MvxBind="Text Price, Converter=IntToPrice" />
        <TextView
            android:id="@+id/car_item_template_year_text"
            android:layout_alignParentLeft="true"
            android:layout_above="@+id/car_item_template_mileage_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Year"
            android:textSize="@dimen/car_item_template_detail_text_size"
            local:MvxBind="Text Year, Converter=EmptyShortCheck, ConverterParameter='No Year'" />
        <TextView
            android:id="@+id/car_item_template_mileage_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/car_item_template_location_text"
            android:layout_alignParentLeft="true"
            android:text="Mileage"
            android:textSize="@dimen/car_item_template_detail_text_size"
            local:MvxBind="Text Mileage, Converter=IntToMileage, ConverterParameter='No Mileage'" />
        <TextView
            android:id="@+id/car_item_template_location_text"
            android:text="Location"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:textSize="@dimen/car_item_template_detail_text_size"
            local:MvxBind="Text Location, Converter=EmptyStringCheck, ConverterParameter='No Location'" />
    </RelativeLayout>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/generic_graydivider" />
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

所以这是解决问题的方法。正如您在上面的模板中看到的那样,TextViews的宽度都设置为wrap_content。我将其更改为固定值,现在问题不再发生了。

不幸的是,我仍然不知道是什么导致列表在SwipeRefreshLayout中包含时以这种方式响应:(但现在这样做。