2017-09-01 43 views
1

我有我的Android應用程序佈局之一的GridView。我試圖在Gridview的中心設置Item,但它始終停留在左側。我在StackOverflow中搜索了許多類似的問題,但沒有解決我的問題。我的XML如下所示。讓我知道是否有人可以幫助我在中心製作GridView項目。Android中的GridView項目在中心

<FrameLayout 
    android:id="@+id/framecaregory" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/second" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="?actionBarSize"> 

    <GridView 
     android:id="@+id/gridviewcategory" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/lite_color" 
     android:numColumns="5" 
     android:visibility="gone"> 

    </GridView> 
</FrameLayout> 

感謝

+0

你想圖像中心內部,你的GridView我是正確的 –

+0

做u有網格view's項目佈局。如果是提供另一個佈局代碼,請 – 2017-09-01 17:29:08

+0

@Yoni請不要添加「Android - 」問題請參閱[幫助中心標記](https://stackoverflow.com/help/tagging)(在頁面底部)應該避免它。 – jmattheis

回答

0

你想要的東西不依賴於電網的佈局,但它適合於它的子佈局。首先創建另一個layout grid_item_row.xml並提出:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/framecaregory" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    android:padding="10dp" 
    android:gravity="center" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:text="Text in the center" 
     android:textAlignment="center" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

之後適應這種佈局網格佈局