【问题标题】:tiny images when using StaggeredGridLayoutManager使用 StaggeredGridLayoutManager 时的小图像
【发布时间】:2020-01-17 18:30:31
【问题描述】:

我在查看器项目内有一个回收器视图,用于很好地显示多达 5 个图像以及一些其他文本。它工作得很好,只是图像看起来非常小,我不确定我哪里出错了。

主视图项目布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:local="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:background="@color/white"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="14dp">
        <TextView
            android:id="@+id/feedItem_txtTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:layout_marginTop="14dp"
            android:textColor="@color/dark_gray"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/feedItem_rvImageGrid"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone" />

        <View
            android:layout_marginTop="5dp"
            android:layout_width="match_parent"
            android:layout_height="15dp"
            android:background="@color/very_light_gray"/>
    </LinearLayout>
</LinearLayout>

图像网格视图项目:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="vertical">
    <ImageView
        android:id="@+id/feedItemImage_ivImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop" />
</LinearLayout>

我用来将网格绑定到 recyclerview 的代码

_layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.Vertical);
_feedItemImageAdapter = new FeedItemImageAdapter(_imageUrlsVisible, _imageUrlsFull);

_rvImageGrid.SetAdapter(_feedItemImageAdapter);
_rvImageGrid.SetLayoutManager(_layoutManager);

不确定您还想看什么,如果我需要提供更多代码示例,请告诉我,我不知道自己做错了什么。

【问题讨论】:

  • 对不起,我无法重现这个问题,您能否分享一个基本的演示,以便我们进行测试?
  • 早上我可以使用我的工作计算机时,我将着手获取一个示例项目

标签: xamarin.android staggeredgridlayoutmanager


【解决方案1】:

一种可能性是您的图像尺寸本身很小。 我尝试通过使用不同尺寸的图片来重现这个问题,当图像网格viewholder项如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
    android:id="@+id/feedItemImage_ivImage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop" />
 </LinearLayout>

结果是:

但是我们可以将ImageView的父属性调整为

android:layout_width="match_parent"
android:layout_height="match_parent"

所以当我们使用下面的代码时:

<?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="match_parent">
<ImageView
    android:id="@+id/feedItemImage_ivImage"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop" />
</LinearLayout>

现在,我们会发现图片会调整到合适的大小,但同时图片会失真和模糊。

【讨论】:

  • 将线性布局更改为 match_parent 解决了我的问题,它们有点小,我将与我的团队合作让这些图像更大,谢谢
猜你喜欢
  • 2020-09-26
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-15
  • 1970-01-01
  • 1970-01-01
  • 2015-03-25
相关资源
最近更新 更多