2011-10-07 63 views
1

我需要聲明這個GridView的programaticalle,全部用Java代碼:如何以編程方式聲明此GridView(Java代碼)?

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/gridview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:columnWidth="90dp" 
android:numColumns="auto_fit" 
android:verticalSpacing="10dp" 
android:horizontalSpacing="10dp" 
android:stretchMode="columnWidth" 
android:gravity="center" 
/> 

我該怎麼辦呢?我正在尋找代碼示例和檢查的文件,但我不能找到辦法:S

感謝

回答

5

你檢查文檔?一切都在gridview documentation。例如,相當於android:numColumns的代碼是setNumColumns(int)。 對於像id這樣的東西,您需要返回查看文檔。寬度和高度將使用LayoutParams進行設置。