<?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:columnWidth="90dp" android:stretchMode="columnWidth" android:gravity="center"></GridView> <!--numColumns 每行的數量 --> <!--verticalSpacing 高 間距 --> <!--horizontalSpacing 寬 間距 --> <!--columnWidth 列寬 --> <!--gravity 位置 --> <!--stretchMode 縮放模式 -->
import android.app.Activity; import android.os.Bundle; import android.widget.GridView; public class mainActivity extends Activity { GridView gv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gv = (GridView) findViewById(R.id.gv); gv.setAdapter(new imgadapter(this)); //imgadapter 繼承至baseadapter } }
版權聲明:本文爲博主原創文章,未經博主容許不得轉載。html