GridView을 java로 만들고 싶습니다. XML을 사용하고 싶지 않습니다. 아래 예제는 XML을 레이아웃으로 사용합니다. 그것은 3 열을 보여줍니다. Java 만 사용하여 설정을 수행하려고합니다.Android 프로그래밍에서 XML을 사용하지 않고 Java로 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>
"XML을 사용하고 싶지 않습니다"- 왜 그런가요? – CommonsWare