ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 갤러리를 이용한 커버플로우 만들기
    안드로이드/학습&강좌 2011. 6. 11. 17:38
    커버플로우 효과를 갤러리를 이용해서 대충이나마 구현해 보자면, Adapter하나에 

    포지션 값을 이용해서 처리 해 보았다. 연습삼아 만들어 본것이라 허접해도 너그러이 용서 해 주길 바란다. ㅎ

     대략의 효과는  이런식이다 앞뒤에 굴곡을 주고 싶으나.. 좀더 연구해 봐야 할 것 같다ㅎ;;

    012

     
     layout 은 
     
    package org.androidpeople.gallery;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.res.TypedArray;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageView;
    import android.widget.AdapterView.OnItemClickListener;
    
    public class GalleryExample extends Activity {
    
        private Gallery gallery;
        private ImageView imgView;
    
        private Integer[] Imgid = {
                R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4, R.drawable.a_5, R.drawable.a_6, R.drawable.a_7
        };
        
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            imgView = (ImageView)findViewById(R.id.ImageView01);	
            imgView.setImageResource(Imgid[0]);
            
             gallery = (Gallery) findViewById(R.id.examplegallery);
             gallery.setAdapter(new AddImgAdp(this));
    
             gallery.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView parent, View v, int position, long id) {
                    imgView.setImageResource(Imgid[position]); 
                }
            });
    
        }
    
        public class AddImgAdp extends BaseAdapter {
            int GalItemBg;
            private Context cont;
    
            public AddImgAdp(Context c) {
                cont = c;
                TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
                GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
                typArray.recycle();
            }
    
            public int getCount() {
                return Imgid.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 imgView = new ImageView(cont);
                imgView.setImageResource(Imgid[position]);
                imgView.setLayoutParams(new Gallery.LayoutParams(200, 200));
                imgView.setScaleType(ImageView.ScaleType.FIT_XY);
                imgView.setBackgroundResource(GalItemBg);
    
                return imgView;
            }
        }
    
    }
    
    

     

    자바 코드
    
    package org.androidpeople.gallery;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.res.TypedArray;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageView;
    import android.widget.AdapterView.OnItemClickListener;
    
    public class GalleryExample extends Activity {
    
        private Gallery gallery;
        private ImageView imgView;
    
        private Integer[] Imgid = {
                R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4, R.drawable.a_5, R.drawable.a_6, R.drawable.a_7
        };
        
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            imgView = (ImageView)findViewById(R.id.ImageView01);	
            imgView.setImageResource(Imgid[0]);
            
             gallery = (Gallery) findViewById(R.id.examplegallery);
             gallery.setAdapter(new AddImgAdp(this));
    
             gallery.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView parent, View v, int position, long id) {
                    imgView.setImageResource(Imgid[position]); 
                }
            });
    
        }
    
        public class AddImgAdp extends BaseAdapter {
            int GalItemBg;
            private Context cont;
    
            public AddImgAdp(Context c) {
                cont = c;
                TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
                GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
                typArray.recycle();
            }
    
            public int getCount() {
                return Imgid.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 imgView = new ImageView(cont);
                imgView.setImageResource(Imgid[position]);
                imgView.setLayoutParams(new Gallery.LayoutParams(200, 200));
                imgView.setScaleType(ImageView.ScaleType.FIT_XY);
                imgView.setBackgroundResource(GalItemBg);
    
                return imgView;
            }
        }
    
    }
    
    

    포스팅을 하려고 이것 저것 연구하다 보니 되려 더 공부를 하게 되는것 같다.

    ㅎ.ㅎ 다들 열공~

    댓글 1

COPYRIGHT 2010 EpoNg. ALL RIGHTS RESERVED.