2012-04-26 17 views
0

現在、GridViewを実装しています。GridViewは、任意の数の要素を保持するカスタムアダプタに接続されています。GridViewの中央のViewgroupを水平方向と垂直方向に合わせる

これらの各要素は、ImageViewと2つのTextViewを持つ垂直LinearLayoutで構成されるカスタムViewGroupに表示されます。私は利用可能な画面の不動産に基づいて、ViewGroupの幅を計算していて、グリッドの中に水平方向と垂直方向に中心を合わせたいと思っています。問題は、アイテムが画面の左端(パディングなし)と画面の右端(パディングなし)に表示されることです。 GridView全体にパディングやマージンを設定した場合、スクロールバーは画面の境界線ではなく項目の横に表示されます。その理由は、私はGridViewにパディングを設定したいが、その中に要素を配置したくないからです。ここで

は、GridViewのための私のコードです:DIMEN/launch_grid_padding @

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/launchLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <com.markupartist.android.widget.ActionBar 
      android:id="@+id/actionbar" 
      style="@style/ActionBar" 
     /> 

    <GridView 
      android:id="@+id/grid" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
     android:verticalSpacing="@dimen/launch_grid_padding" 
     android:horizontalSpacing="@dimen/launch_grid_padding" 
      android:numColumns="auto_fit" 
      android:stretchMode="columnWidth" 
      android:gravity="center" 
      android:listSelector="#00000000" 
      android:layout_marginTop="@dimen/launch_grid_padding" 
      android:layout_marginBottom="@dimen/launch_grid_padding" 
    /> 
    </LinearLayout> 

</RelativeLayout> 

は20dpの値を持ちます。

そして、これは私のカスタムのViewGroupのレイアウトです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@drawable/rounded_box" 
    android:layout_gravity="center" 
> 
    <ImageView 
     android:id="@+id/img" 
     android:layout_width="120dp" 
     android:layout_height="84dp" 
     android:scaleType="centerInside" 
    /> 
    <TextView 
     android:id="@+id/identifier1" 
     android:layout_width="120dp" 
     android:layout_height="wrap_content" 
     android:background="@android:color/white" 
     android:gravity="left|center_vertical" 
     android:typeface="sans" 
     android:textStyle="bold" 
     android:textColor="#333333" 
     android:textSize="12dp" 
     android:lines="1" 
     android:ellipsize="marquee" 
    /> 
    <TextView 
     android:id="@+id/identifier2" 
     android:layout_width="120dp" 
     android:layout_height="wrap_content" 
     android:textColor="#333333" 
     android:background="@android:color/white" 
     android:gravity="left|center_vertical" 
     android:textSize="10dp" 
     android:lines="1" 
    /> 
</LinearLayout> 

これは、多かれ少なかれである私が(アイテムの可変量で)を達成しようとしています:

http://www.appdesignvault.com/wp-content/uploads/2012/04/iphone-app-design-bizapp-5.jpg

どんな助けでも大歓迎です!

答えて

4

を指定し、android:stretchMode="spacingWidthUniform"と指定して、android:horizontalSpacingandroid:verticalSpacingを削除します。私はその問題を解決することを願っています。

+0

ありがとうございました。多かれ少なかれ解決しました。私はまだverticalSpacingを定義する必要があります。 –

関連する問題