程序代码结构如下: MainActivity程序的入口类,BookLayout自定义布局,填充MainActivity。BookAdapter是BookLayout的Adapter,主要用来定义Layout中子View,我这里用的ImageView。MainActivity代码:public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); BookLayout bk = new BookLayout(this); List<Integer> str = new ArrayList<Integer>(); str.add(R.drawable.tiankong); str.add(R.drawable.qian); str.add(R.drawable.haer); str.add(R.drawable.gong);
BookAdapter ba = new BookAdapter(this); ba.addItem(str); bk.setPageAdapter(ba); setContentView(bk); } }将资源包中4张Image的id放到List中。BookAdapter主要方法如下:public View getView(int position) {