JavaでGridViewを作成したいのですが、XMLを使用したくありません。以下の例は、レイアウトとしてのXMLです。3列表示されます。Javaのみを使用してその設定を実現したいと思います。
私のアクティビティでは、代わりにGridView gv = (GridView) findViewById (R.id.gridview);
私は使用しますGridView gv = new GridView (this);
。
今、私の唯一の問題は、列が1つしかないことです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
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"/>
</LinearLayout>