package com.contacts; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.Gallery; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.LinearLayout.LayoutParams; public class ContactsActivity extends Activity implements OnItemSelectedListener { /** Called when the activity is first created. */ private galleryAdapter adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Gallery gallery=(Gallery)findViewById(R.id.gallery); adapter=new galleryAdapter(this); gallery.setAdapter(adapter); gallery.setSpacing(5); gallery.setOnItemSelectedListener(this); } public void onItemSelected(AdapterView<?> parent, View view, int position,long id) { adapter.setSelectItem(position); //当滑动时,事件响应,调用适配器中的这个方法。 } @Override public void onNothingSelected(AdapterView<?> arg0) {//抽象方法,必须实现 // TODO Auto-generated method stub } }
Main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" /> </LinearLayout>
还有个动画的配置文件,这里就不贴了,感兴趣的可以下载全部工程。