{"id":134,"date":"2017-04-15T13:59:05","date_gmt":"2017-04-15T05:59:05","guid":{"rendered":"http:\/\/av16874667.imwork.net:13582\/?p=134"},"modified":"2017-04-15T13:59:05","modified_gmt":"2017-04-15T05:59:05","slug":"android-viewpage-%e7%9a%84pageadapter","status":"publish","type":"post","link":"https:\/\/www.dd-home.top\/?p=134","title":{"rendered":"Android ViewPage \u7684PageAdapter"},"content":{"rendered":"<p><!--more--><\/p>\n<p>1.FragmentStatePageAdapter<\/p>\n<p><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1, 'Microsoft YaHei';\">\u9002\u7528\u4e0elist\u4e4b\u7c7b\u7684\u96c6\u5408,\u4e0d\u4f1a\u5927\u91cf\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d,\u53ea\u662f\u7f13\u5b58\u4e86\u90e8\u5206<\/span><\/p>\n<pre>\/**\n * Implementation of {@link android.support.v4.view.PagerAdapter} that\n * uses a {@link Fragment} to manage each page. This class also handles\n * saving and restoring of fragment's state.\n *\n * &lt;p&gt;This version of the pager is more useful when there are a large number\n * of pages, working more like a list view. \u00a0When pages are not visible to\n * the user, their entire fragment may be destroyed, only keeping the saved\n * state of that fragment. \u00a0This allows the pager to hold on to much less\n * memory associated with each visited page as compared to\n * {@link FragmentPagerAdapter} at the cost of potentially more overhead when\n * switching between pages.\n *\n * &lt;p&gt;When using FragmentPagerAdapter the host ViewPager must have a\n * valid ID set.&lt;\/p&gt;\n *\n * &lt;p&gt;Subclasses only need to implement {@link #getItem(int)}\n * and {@link #getCount()} to have a working adapter.\n *\n * &lt;p&gt;Here is an example implementation of a pager containing fragments of\n * lists:\n *\n * {@sample development\/samples\/Support13Demos\/src\/com\/example\/android\/supportv13\/app\/FragmentStatePagerSupport.java\n * \u00a0 \u00a0 \u00a0complete}\n *\n * &lt;p&gt;The &lt;code&gt;R.layout.fragment_pager&lt;\/code&gt; resource of the top-level fragment is:\n *\n * {@sample development\/samples\/Support13Demos\/res\/layout\/fragment_pager.xml\n * \u00a0 \u00a0 \u00a0complete}\n *\n * &lt;p&gt;The &lt;code&gt;R.layout.fragment_pager_list&lt;\/code&gt; resource containing each\n * individual fragment's layout is:\n *\n * {@sample development\/samples\/Support13Demos\/res\/layout\/fragment_pager_list.xml\n * \u00a0 \u00a0 \u00a0complete}\n *\/<\/pre>\n<p>2.FragmentPageAdapter<\/p>\n<p>\u9002\u7528\u4e8e\u5f00\u59cb\u9875\u9762\u7684\u51e0\u4e2aFragment,\u5c11\u91cf\u7684\u9875\u9762\u4f1a\u7f13\u5b58<\/p>\n<pre>\/**\n * Implementation of {@link android.support.v4.view.PagerAdapter} that\n * represents each page as a {@link Fragment} that is persistently\n * kept in the fragment manager as long as the user can return to the page.\n *\n * &lt;p&gt;This version of the pager is best for use when there are a handful of\n * typically more static fragments to be paged through, such as a set of tabs.\n * The fragment of each page the user visits will be kept in memory, though its\n * view hierarchy may be destroyed when not visible. \u00a0This can result in using\n * a significant amount of memory since fragment instances can hold on to an\n * arbitrary amount of state. \u00a0For larger sets of pages, consider\n * {@link FragmentStatePagerAdapter}.\n *\n * &lt;p&gt;When using FragmentPagerAdapter the host ViewPager must have a\n * valid ID set.&lt;\/p&gt;\n *\n * &lt;p&gt;Subclasses only need to implement {@link #getItem(int)}\n * and {@link #getCount()} to have a working adapter.\n *\n * &lt;p&gt;Here is an example implementation of a pager containing fragments of\n * lists:\n *\n * {@sample development\/samples\/Support4Demos\/src\/com\/example\/android\/supportv4\/app\/FragmentPagerSupport.java\n * \u00a0 \u00a0 \u00a0complete}\n *\n * &lt;p&gt;The &lt;code&gt;R.layout.fragment_pager&lt;\/code&gt; resource of the top-level fragment is:\n *\n * {@sample development\/samples\/Support4Demos\/res\/layout\/fragment_pager.xml\n * \u00a0 \u00a0 \u00a0complete}\n *\n * &lt;p&gt;The &lt;code&gt;R.layout.fragment_pager_list&lt;\/code&gt; resource containing each\n * individual fragment's layout is:\n *\n * {@sample development\/samples\/Support4Demos\/res\/layout\/fragment_pager_list.xml\n * \u00a0 \u00a0 \u00a0complete}\n *\/<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134"}],"version-history":[{"count":0,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}