读书人

图片长廊

发布时间: 2012-09-18 16:21:42 作者: rapoo

图片走廊

  <ImageSwitcher        android:id="@+id/switcher"              android:layout_width="fill_parent"               android:layout_height="fill_parent"              android:layout_alignParentTop="true"              android:layout_alignParentLeft="true" />   //上面ImageSwitcher是用来显示图片那块区域的控件                  <Gallery android:id="@+id/gallery"        android:background="#55000000"              android:layout_width="fill_parent"               android:layout_height="60dp"              android:layout_alignParentBottom="true"              android:layout_alignParentLeft="true"              android:gravity="center_vertical"               android:spacing="16dp" />//Gallery 是来控制低下那个图标列表索引用的  public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);//是使这个Activity没有titleBar,进而这个图片显示区域会增大//下面对BaseAdapter 进行了封装,这里是定义自己的适配器,其中getView()返回要显示的那个ImageView public class ImageAdapter extends BaseAdapter {        public ImageAdapter(Context c) {            mContext = c;        }        public int getCount() {            return mThumbIds.length;        }        public Object getItem(int position) {            return position;        }        public long getItemId(int position) {            return position;        }        public View getView(int position, View convertView, ViewGroup parent) {            ImageView i = new ImageView(mContext); //动态生成一个ImageView            i.setImageResource(mThumbIds[position]);//设置这张图片的源文件            i.setAdjustViewBounds(true);            i.setLayoutParams(new Gallery.LayoutParams(                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));//设置图片框的大小            i.setBackgroundResource(R.drawable.picture_frame);//设置图片的背景            return i;        }        private Context mContext;    }

读书人网 >移动开发

热点推荐