GridView自定义间距问题

时间:2015-12-08 07:45:52

标签: android view grid

美好的一天。我有一个包含24个图像的gridView。我有3行,8列。列应该用4x4分隔,所以4列和SPACE分开,然后是另外4列。问题是我遇到了很多不必要的问题。首先我尝试使用verticalSpacing,但纯粹不需要,因为它会占用网格视图的完整项目,但我只需要在8列(4x4)之间留出空间。所以我试图在代码中动态地给出一个上边距到我的单个图像视图,只要我的位置到达我想要间隔的项目。所以我在我的适配器中使用此代码完成。

   if (position >= 12 && position <= 14) {
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) imageView.getLayoutParams();
            layoutParams.topMargin = 50;
            imageView.setLayoutParams(layoutParams);
        }`

这是有效的。但问题是,间隔的图像视图被挤压了很多,看起来很丑。所以通过谷歌搜索我发现纯粹没有更接近我的情况。请你帮帮我,告诉我是什么我可以在我想要的物品之间只留空间而不会挤压它们。

这是网格视图布局的xml。

    <?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:background="@color/dark_background_color"
    android:layout_height="match_parent">

    <GridView
        android:id="@+id/dynamic_grid_view"
        android:background="#dfd8d8"
        android:layout_margin="@dimen/vertical_margin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numColumns="3"
        android:gravity="center"
        />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/arrange_poster_info_button"
            style="@style/PrimaryButton"
            android:layout_centerHorizontal="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/info"
            />
    </RelativeLayout>

</LinearLayout>

以下是单项xml的代码

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/imagesHolderFrame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <com.github.siyamed.shapeimageview.RoundedImageView
        android:id="@+id/stripsSingleimage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:siRadius="0dp"
        app:siBorderWidth="1dp"
        app:siBorderColor="#ffffff"
        app:siSquare="true"/>

    <View
        android:id="@+id/overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/selection_overlay" />
</FrameLayout>

这里不好添加链接到图像,我的图像挤压,看起来很难看。 [正如你所看到的,第二排的第一项被挤压了

http://crm.socialobjects.am/attachments/7811/Screenshot_2015-12-08-10-09-28.png

0 个答案:

没有答案