gridview有组织的项目,如instagram



如果我在网格视图中从parse.com获取图片,一切都很好,我的图像都显示出来了,但不是我想要的样子。我的结果

这就是我想要的样子instagram外观

这是我的网格代码:

<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 中

尝试在imageview中使用wrap_content或实际图像维度,而不是match_parent和scaleType的center。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);
    }
}

最新更新