19

Androidグリッドビューでは、グリッドビューの行の間に余分なスペースがあります。グリッドビューにスペースを追加していません。

これが私のxmlファイルです

        <GridView
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/grid"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:horizontalSpacing="5px"
                android:numColumns="3"
                android:columnWidth="50dip"
                 android:verticalSpacing="0dip"
                android:gravity="center"
                />

グリッドビューにビューを追加しているimageviewの他のxmlは

        <ImageView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/singlePhoto"
            android:layout_gravity="top"
            android:layout_width="145dip"
            android:layout_height="145dip"
            android:layout_marginTop="0dip"
            android:layout_marginBottom="0dip"
            >
        </ImageView>

Adapterクラスでは、コードは次のとおりです。

        if(mView == null){
            mView = mLayoutInflater.inflate(R.layout.newsgridthumbpic, null);
                }

                ImageView mImage = (ImageView)mView.findViewById(R.id.singlePhoto);
                PhotoGridInfoSet mInfo = (PhotoGridInfoSet)details.get(position);
                if(mImage != null){
                mImage.setTag(mInfo.getPhotoThumbNailString());
                mImage.setVerticalScrollBarEnabled(true);
                mImage.setVerticalFadingEdgeEnabled(true);
                }
        }!

スペースはgridviewの行の間にあります。コードのどこにもスペースを追加していませんが、垂直方向のスペースがあります。グリッドビューの行の間にスペースがある理由がわかりません。このスペースは、hdpiデバイス/エミュレーターには表示されません。この問題は、mdpiおよびldpiデバイス/エミュレーターにあります。

参考画像。 これが今起こっていることです。

4

8 に答える 8

42

私はこの問題の解決策を得ました。

これを解決するには、xmlファイルに1行追加する必要があります

android:adjustViewBounds="true"

そしてこれを追加した後。スペースは現在表示されていません

于 2012-02-04T16:37:21.520 に答える
2

最後の2行をgridViewに入れるだけです

<GridView
        android:numColumns="2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/gridView"
        android:horizontalSpacing="0dip"
        android:verticalSpacing="0dip"/>
于 2016-02-17T13:44:50.700 に答える
0

次の行をurgetView()メソッドに入れます。

mImage.setPadding(0, 0, 0, 0);

これがお役に立てば幸いです。

于 2012-02-03T07:24:56.803 に答える
0

アスペクト比を維持しながら、50dpの列幅に合うように画像が拡大縮小されているようです。これは、垂直レイアウトに埋められていないスペースの束を導入しています。列の幅を50dpにする場合、これらの間隔の問題を解決する最も簡単な方法は、imageviewの幅を50dpに調整し、それに比例してimageviewsの高さを調整することです。

于 2012-02-03T07:25:49.093 に答える
0

「newsgridthumbpic」レイアウトに、グリッドビュー要素よりも高い高さの余分なパディングや背景画像が含まれていないことを確認してください。

また、column_widthを50dipとして指定しているが、「imageview」の幅が145dipであることを再確認してください。

于 2012-02-03T10:21:11.667 に答える
0

グリッドビューでandroid:verticalSpacingを負の値に設定します。垂直方向のスペースが削除されます。

(例:android:verticalSpacing = "-10dp")

適切な値を取得するために、いくつかの数値でテストします

于 2015-09-15T13:18:08.773 に答える
0
<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/grid"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:horizontalSpacing="5px"
    android:numColumns="3"
    android:columnWidth="50dip"
     android:verticalSpacing="0dip"
    android:gravity="center"/>

<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/singlePhoto"
    android:layout_width="145dip"
    android:layout_height="145dip"
    android:scaleType="fitXY">
</ImageView>
于 2016-02-17T11:28:07.067 に答える
0

RecyclerViewを使用しているときに、同じ問題を修正する別の方法があります。

GridLayoutManager(this、6)で6を指定したように、 SpanCountの数を渡し、SpanCountを変更して、RecyclerViewのアイテム間のギャップを増減します。

このサンプルコードを確認してください-

GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 6);
  rvSizes.setLayoutManager(gridLayoutManager);
  SizeSelectorAdaptersizeChooserAdapter = new SizeSelectorAdapter(this, sizes);
  rvSizes.setAdapter(sizeChooserAdapter);

これがお役に立てば幸いです。ありがとうございました

于 2020-07-03T14:49:24.970 に答える