【问题标题】:How to make grid views in android similar to Instagram?如何在 android 中制作类似于 Instagram 的网格视图?
【发布时间】:2020-05-16 09:37:45
【问题描述】:

我知道如何使用 3rd 方库在 android 中裁剪图像,但我想根据用户偏好(3x3、3x1 等)将单张图片拆分为多张图片作为 Instagram Feed 的网格

就像:https://play.google.com/store/apps/details?id=com.instagrid.free&hl=en

如何解决这个问题?有什么特别的图书馆吗?

【问题讨论】:

    标签: android gridview imageview cropper


    【解决方案1】:

    假设您有这样的裁剪图像的功能:

    public Image crop(Image src, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY);
    

    此示例代码将帮助您将图片拆分为 R 行和 C 列:

    public List<Image> split(Image src, int r, int c) {
        List<Image> result = new ArrayList<>();
    
        int topLeftX, topLeftY, bottomRightX, bottomRightY;
    
        int res_height = src.height / r;
        int res_width = src.width / c;
    
        for (int i = 0; i < r; i++) {
            topLeftX = i * res_height;
            bottomRightX = (i + 1) * res_height;
            for (int j = 0; j < c; j++) {
                topLeftY = j * res_width;
                bottomRightY = (j + 1) * res_width;
    
                result.add(crop(src, topLeftX, topLeftY, bottomRightX, bottomRightY));
            }
        }
    
        return result;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多