9

私は、GridViewアルファベットの写真を表示する を持っていますが、最後の行では毎回アルファベットが少なくなります。そして、最後の行は左揃えです。これは見栄えが悪いので、最後の行を中央に配置したいと思います。

私のGridViewコード:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/grid_view"
    android:layout_width="fill_parent"
    android:layout_marginRight="20dp"
    android:layout_marginTop="20dp"
    android:layout_height="fill_parent"
    android:numColumns="auto_fit"
    android:columnWidth="70dp"
    android:horizontalSpacing="10dp"
    android:verticalSpacing="20dp"
    android:gravity="center"
    android:stretchMode="spacingWidthUniform" >  

</GridView>

ここに画像の説明を入力

ここに画像の説明を入力

4

4 に答える 4

0

私は同じ問題を抱えていますが、2つのグリッドビューを使用してこれを管理しました。最初のグリッドビューには最後の行を除く行が表示され、2番目のグリッドビューには最後の行が表示されます。これは、私が必要とするものを達成するための最も簡単な方法です。私はより良い解決策を見つけていません。素敵でシンプルな方法も楽しみにしています。

于 2015-01-31T09:31:28.127 に答える
-1

相対レイアウト内でグリッド行を中央に配置してandroid:layout_centerHorizontal="true"から、アルファベットに追加できImageViewます。ImageViewそれらが'sであると仮定します。

したがって、次のGridViewようにラップされます。

<RelativeLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_cotent"
    android:orientation="horizontal" >

    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/grid_view"
        android:layout_width="fill_parent"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:layout_height="fill_parent"
        android:numColumns="auto_fit"
        android:columnWidth="70dp"
        android:horizontalSpacing="10dp"
        android:verticalSpacing="20dp"
        android:gravity="center"
        android:stretchMode="spacingWidthUniform" >  

    </GridView>
</RelativeLayout>

そして、個々のアルファベット画像は次のandroid:layout_centerHorizontal="true"ようにする必要があります:

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_centerHorizontal="true"
</ImageView>
于 2014-01-19T17:41:26.167 に答える