Horizontal View Swiping with ViewPager
ã¡ãã£ã¨ã»ã£ããããã«ãã¦ãããã¿ãæãèµ·ããã¦ã¿ã¾ãã以åこちらã§æ¸ãããã¿ã§ãã以åã®è¨äºã§ã¯å®è¡ããã¾ã§ã«æ¢ã¾ãã¾ããããä»åã¯ã¡ãã£ã¨ä¸èº«ãé¤ãã¦ã¿ããã¨ã«ãã¾ãã
ãã®ãµã³ãã«ã§ã¯ViewPagerã¨ããã¯ã©ã¹ã使ããã¦ãã¾ãããã®ViewPagerã§ãããAndroid Developersã§æ¤ç´¢ãã¦ããªãã¡ã¬ã³ã¹ãåºã¦ãã¾ãããçç±ã¯åããã¾ãããããããããã®ViewPagerã¯ã©ã¹ãCompatibility Packageã ããã§ã¯ãªããã¨äºæ³ãã¾ããCompatibility Packageã¨ã¯HoneyCombåãã«ãªãªã¼ã¹ãããFragmentãAndroid3.0以åã§ã使ããããã«ããããã®ããã±ã¼ã¸ã§ãããã¡ãããã®ãµã³ãã«ã§ãCompatibility Packageã使ã£ã¦ãã¾ãã
ã§ãä½ã§ãªãã¡ã¬ã³ã¹ããªããã§ãããï¼ã½ã¼ã¹ãè¦ãã£ã¦ãã¨ãªãã§ãããããã
ã¾ããããªãã¨ã¯ãã¦ããããã®ãµã³ãã«ã§ãã£ã¦ãããã¨ã¯ã¨ã£ã¦ãã·ã³ãã«ã§ããè¦ã®é¨åã¯ãã¡ãã
private AwesomePagerAdapter awesomeAdapter; // çç¥ awesomeAdapter = new AwesomePagerAdapter(); awesomePager = (ViewPager) findViewById(R.id.awesomepager); awesomePager.setAdapter(awesomeAdapter);
ãããï¼ä½ãè¦ããã¨ãããã¿ã¼ã³ã§ããããããã§ãããªã¹ãã«ã¢ããã¿ãå·®ãè¾¼ããã¿ã¼ã³ã¨ã¾ã£ããåãã§ããã¤ã¾ããã¼ã¸ã«ã¢ããã¿ãå·®ãè¾¼ãããã§ããå¾ã¯ViewPagerãå¿
è¦ãªã¨ãã«å¿
è¦ãªãã¼ã¸ãã¢ããã¿ã«åãåããã¦ããããã§ããããããè¦äºãªã¢ããã¸ã¼âª
ã§ã¯èå¿ãªã¢ããã¿ (PagerAdapter) å´ã®ã³ã¼ããè¦ã¦ã¿ã¾ãããªã¼ãã¼ã©ã¤ããã¹ãã¡ã½ããã¯ä»¥ä¸ã®8ã¤ã§ãã
ã¡ã½ããå | 説æ |
---|---|
int getCount() | ãã¼ã¸ã®æ°ãè¿ã |
Object instantiateItem(View collection, int position) | positionçªç®ã®ViewãViewPagerã«è¿½å ãã |
void destroyItem(View collection, int position, Object view) | positionçªç®ã®ViewãViewPagerããåé¤ãã |
boolean isViewFromObject(View view, Object object) | ï¼ï¼ï¼ |
void finishUpdate(View arg0) | Viewãåãæ¿ãã£ãã¿ã¤ãã³ã°ã§å¼ã°ãã |
void restoreState(Parcelable arg0, ClassLoader arg1) | ç¶æ ã復帰ããããã®ã¡ã½ãã |
Parcelable saveState() | ç¶æ ãä¿åããããã®ã¡ã½ãã |
void startUpdate(View arg0) | Viewã®åãæ¿ãããå§ã¾ãã¿ã¤ãã³ã°ã§å¼ã°ãã |
ããåãããªãã®ãisViewFromObjectããã°ã§ç¢ºèªããã¨ãããããªãã®åæ°å¼ã°ãã¦ãã¾ãããµã³ãã«ã®ä¸èº«ã¯ãããªæãã
@Override public boolean isViewFromObject(View view, Object object) { return view==((TextView)object); }
ï¼ï¼ï¼ããåããããã¾ãããã (ãªã¤ãªã¤) ã
こちらのブログã«ãããããã«ãæ¬ ç¹ã¯åãã¼ã¸ãã¨ã«ç¶æ ãè¦ããå¿ è¦ãããå ´åããªãããã®ä»æããèªåã§ä»è¾¼ã¾ãªãã¨ãããªãç¹ã§ãããã¡ãªã¿ã«saveStateãrestoreStateã¯Viewãåãæ¿ãããã¨ã«å¼ã°ããã®ã§ã¯ãªããViewPagerå ¨ä½ãããã¯ã°ã©ã¦ã³ãã«é·ç§»ãããããã©ã¢ã°ã©ã¦ã³ãã«é·ç§»ãããããã¨ãã«å¼ã°ãã¾ãã
以ä¸ãViewPagerã®ãµã³ãã«ã«ã¤ãã¦è¦ã¦ãã¾ããããå人çãªææ³ãè¨ãã¨ä½¿ããªãããªããã§ããViewPagerãã®ãã®ããããªã«ä½¿ãåæãããæãã§ã¯ããã¾ããããä½ãããCompatibility Packageãã¡ãã£ã¨ã»ã»ã»ã