我在v7.widget.RecyclerView中遇到问题。我有一个来自应用程序用户的“帖子”,其中显示了他们先前添加的所有图像以及任何其他附件(文档,视频等)。有一个选项可以编辑现有帖子。
我有一个EditPost xml文件,该文件嵌入了一个名为attachment_item的文件。反过来,这会嵌入一个名为EditAttachmentsLayout的xml文件。如果需要,我可以从前两个文件中发布代码,但我认为问题不存在。
EditAttachmentsLayout页面使用2个RecyclerViews;一个用于图像,另一个用于其他文件。代码在这里:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/edit_images_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="@+id/edit_attachments_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
问题是,当附件回收器有要显示的项目时,它会在第一张(也是第一张)图像上放置某种叠加层,如下所示:
如果我按了缩略图上的十字按钮(或附件本身的十字按钮,附件将被删除,然后图像将出现,如下所示:
好像回收者在列表中的第一张图像上放置了某种覆盖物。我已经尝试了各种方法来解决它,例如增加间距以试图迫使两个回收站分开,并切换到GridView,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:rowCount="4">
<android.support.v7.widget.RecyclerView android:id="@+id/edit_images_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_row="0"
android:scrollbars="none"/>
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_marginBottom="10dp"/>
<android.support.v7.widget.RecyclerView android:id="@+id/edit_attachments_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_row="2"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:scrollbars="none"/>
</GridLayout>
[不幸的是,问题仍然存在。该图像始终被覆盖,直到我移除附件。
任何想法...?我为此感到难过。
编辑:
这里是设置回收者视图的代码:
private void SetupRecycler()
{
RecyclerView imagesRecyclerView = FindViewById<RecyclerView>(Resource.Id.edit_images_recycler);
RecyclerView attachmentsRecyclerView = FindViewById<RecyclerView>(Resource.Id.edit_attachments_recycler);
LinearLayoutManager imagesLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);
LinearLayoutManager attachmentsLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.Vertical, false);
imagesRecyclerView.SetLayoutManager(imagesLayoutManager);
attachmentsRecyclerView.SetLayoutManager(attachmentsLayoutManager);
IList<DeviceFile> localFiles = _fileUtil.GetLocalFiles(_postEntry.MobileId);
_editImageAdapter = new EditImageAdapter(_postEntry, localFiles.Where(file => file.IsThumbnail).ToList());
_editAttachmentAdapter = new EditAttachmentAdapter(_postEntry, localFiles.Where(file => !file.IsThumbnail).ToList());
imagesRecyclerView.SetAdapter(_editImageAdapter);
attachmentsRecyclerView.SetAdapter(_editAttachmentAdapter);
_editImageAdapter.LocalFileDeleted += LocalFileDeleted;
_editImageAdapter.UploadedFileDeleted += UploadedFileDeleted;
_editAttachmentAdapter.LocalAttachmentDeleted += LocalFileDeleted;
_editAttachmentAdapter.UploadedAttachmentDeleted += UploadedFileDeleted;
}
建议:
尝试将父级线性布局高度设置为match_parent
// 此行
您是否尝试查看主线程是否有问题RunOnUIThread(() => {})
-更新适配器
尝试使用以下方法通知回收站适配器更改:
_ editImageAdapter.NotifiyDatasetChanged()_editImageAdapter.NotifiyDatasetChanged()