gridview 组织项目,如 instagram

gridview organized items like instagram

我在 android 应用程序中工作,我在网格视图中从 parse.com 获取照片, 一切正常,并且显示了我的图像,但不是我想要的样子。 my result

这就是我想要的样子 instagram look

这是我的网格代码:

<GridView 
    android:id="@+id/gridview"
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:numColumns="3"
    android:horizontalSpacing="1dp"
    android:verticalSpacing="1dp"
    android:layout_below="@+id/header_shadow"
    android:listSelector="#00FFFFFF"/>

这是我的商品:

<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/photo"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:scaleType="fitXY"/>

图片以方形尺寸保存,缩略图以200x200显示

尝试使用 wrap_content 或图像视图中的实际图像尺寸而不是 match_parent 和中心的 scaleType。 fitXY 允许您缩放图像,而不是保持它们的纵横比。

http://www.techrepublic.com/article/clear-up-ambiguity-about-android-image-view-scale-types-with-this-guide/

此外,本指南还提供了很多关于不同贴合类型的详细信息

http://www.peachpit.com/articles/article.aspx?p=1846580&seqNum=2

将此添加到您的布局中。它应该可以解决您的问题:

public class SquareImageView extends AppCompatImageView {
    public SquareImageView(Context context) {
        super(context);
    }

    public SquareImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, widthMeasureSpec);
    }
}