1,xml布局
<RelativeLayout 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" > <Gallery android:id="@+id/gallery" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> |
2,activity代码
public class MainActivity extends Activity { private int[]images = new int[]{ R.drawable.cat, R.drawable.cat1, R.drawable.cattt, R.drawable.cat, R.drawable.cat1, R.drawable.cattt}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Gallery gallery = (Gallery) findViewById(R.id.gallery); gallery.setAdapter(new MyAdapter()); } private class MyAdapter extends BaseAdapter{ @Override @Override @Override @Override } |