【问题标题】:Forcing RecyclerView to display all images as the same size强制 RecyclerView 将所有图像显示为相同大小
【发布时间】:2016-09-20 21:26:02
【问题描述】:

我正在使用 RecyclerView 和 GridLayoutManager 来开发画廊。我希望纵向和横向图像在网格中显示为相同大小。我该怎么做?

【问题讨论】:

  • 我尝试设置边距并使用 setScaleType(ImageView.ScaleType.CENTER_CROP)。我也试过有人写的方法。它们都只会导致人像图像旁边的图像失真。
  • 你必须发布你的代码你尝试了什么结果和你想要什么?
  • 如果你想让它们成比例,即没有拉伸,那么您可能必须使用一些逻辑裁剪图像并创建新的位图。有很多关于在 Android 中以编程方式裁剪图像的帖子 - 只需搜索即可。

标签: android android-layout android-recyclerview


【解决方案1】:

您面临什么问题。只需将固定大小添加到您的图像视图。

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="100dp"
    android:layout_height="100dp"
     />

【讨论】:

    【解决方案2】:

    这对我有用。

       if (image.getWidth() >= image.getHeight()){
      image = Bitmap.createBitmap(image, image.getWidth() / 2 - image.getHeight() / 2, 0,
          200,200);}
    else
    {image = Bitmap.createBitmap(image, 0, image.getHeight() / 2 - image.getWidth() / 2,
        200, 200);}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 2013-03-24
      • 2013-08-27
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      相关资源
      最近更新 更多