{"id":1037,"date":"2019-02-11T09:18:07","date_gmt":"2019-02-11T00:18:07","guid":{"rendered":"https:\/\/www.charlezz.com\/?p=1037"},"modified":"2019-05-24T17:56:34","modified_gmt":"2019-05-24T08:56:34","slug":"viewpager2-%ed%86%ba%ec%95%84%eb%b3%b4%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/charlezz.com\/?p=1037","title":{"rendered":"ViewPager2 \ud1ba\uc544\ubcf4\uae30"},"content":{"rendered":"<h1>Released ViewPager2!<\/h1>\n<p>\uad6c\uae00\uc774 <a href=\"https:\/\/android-developers.googleblog.com\/2011\/08\/horizontal-view-swiping-with-viewpager.html\">ViewPager<\/a>\ub97c 2011\ub144\uc5d0 \ub9b4\ub9ac\uc988\ud55c \uc774\ud6c4\ub85c \uc0c8\ub85c\uc6b4 \ubc84\uc804\uc778 <a href=\"https:\/\/developer.android.com\/jetpack\/androidx\/releases\/viewpager2#1.0.0-alpha01\">ViewPager2<\/a>(\uc54c\ud30c\ubc84\uc804)\ub97c \ub9b4\ub9ac\uc988 \ud588\uc2b5\ub2c8\ub2e4.\u00a0<br \/>\n\ub9ce\uc740 \uac1c\ubc1c\uc790\ub4e4\uc774 \ud398\uc774\uc9c0\ub2e8\uc704\uc758 \uae30\ub2a5\uc744 \uad6c\ud604\ud558\uae30 \uc704\ud574 \uc774 \ucef4\ud3ec\ub10c\ud2b8\ub97c \uc0ac\uc6a9\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.\u00a0<a href=\"https:\/\/www.charlezz.com\/?attachment_id=1038\" rel=\"attachment wp-att-1038\"><br \/>\n<img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/02\/Material-ViewPagerIndicator.gif\" alt=\"\" width=\"337\" height=\"600\" class=\"aligncenter size-full wp-image-1038\" \/><\/a><a href=\"https:\/\/www.charlezz.com\/?attachment_id=1038\" rel=\"attachment wp-att-1038\"><\/a><a href=\"https:\/\/www.charlezz.com\/?attachment_id=1038\" rel=\"attachment wp-att-1038\"><\/a><\/p>\n<p>\ub9ce\uc740 \uac1c\ubc1c\uc790\ub4e4\uc774 \uc0ac\uc6a9\ud55c\ub2e4\uace0 \ud574\uc11c \uc0ac\uc6a9\ud558\uae30 \uc26c\uc6b4 \ucef4\ud3ec\ub10c\ud2b8\ub294 \uc544\ub2d9\ub2c8\ub2e4. ViewPager\ub97c \ub9cc\ub4e4\uae30\uc704\ud574\uc11c\ub294 Adapter\ub3c4 \uad6c\ud604\ud574\uc57c\ud558\uba70, \uc5b4\ub5a4 \uc5b4\ub311\ud130\ub97c \uad6c\ud604\ud574\uc57c\ud560\uc9c0 \ud56d\uc0c1 \uace0\ubbfc\ud558\uac8c \ub429\ub2c8\ub2e4. FragmentPagerAdapter\ub97c \uc368\uc57c\ud560\uc9c0 \ub610\ub294\u00a0 FragmentStatePagerAdapter\uc368\uc57c\ud558\ub294\uc9c0 \ub9d0\uc774\uc8e0. \uadf8\ub9ac\uace0 Fragment\ub97c \uaf2d \uc0ac\uc6a9\ud574\uc57c\ud558\ub294\uc9c0\ub3c4&#8230;<\/p>\n<div id=\"attachment_1039\" style=\"width: 255px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.charlezz.com\/?attachment_id=1039\" rel=\"attachment wp-att-1039\"><img aria-describedby=\"caption-attachment-1039\" decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/02\/tumblr_odt36lVjis1u4ypbyo3_250.gif\" alt=\"\" width=\"245\" height=\"150\" class=\"wp-image-1039 size-full\" \/><\/a><\/p>\n<p id=\"caption-attachment-1039\" class=\"wp-caption-text\">\uc544\uc544.. \ud504\ub808\uadf8\uba3c\ud2b8 \uc0dd\uba85\uc8fc\uae30&#8230;<\/p>\n<\/div>\n<h2>New feature?<\/h2>\n<p><strong>ViewPager\uc640 \ube44\uad50\ud558\uc5ec \ub2ec\ub77c\uc9c4 \uc0c8\ub85c\uc6b4\uae30\ub2a5<\/strong><\/p>\n<ul>\n<li>RTL \ub808\uc774\uc544\uc6c3 \uc9c0\uc6d0<\/li>\n<li>\uc138\ub85c \ubaa8\ub4dc \uc9c0\uc6d0<\/li>\n<li>\uae30\uc874 ViewPager\uc758 notifyDataSetChanged \ubc84\uadf8 \ubb38\uc81c\ud574\uacb0<\/li>\n<\/ul>\n<p>\uae30\uc874\uc5d0 \uac00\uc9c0\uace0 \uc788\ub358 \ubb38\uc81c\uc810\uc73c\ub85c\ub294\u00a0Right-to-left(RTL) \ub808\uc774\uc544\uc6c3\uc744 \uc9c0\uc6d0\ud558\uc9c0 \uc54a\uace0, \uc138\ub85c\ubaa8\ub4dc \ub610\ud55c \uc5c6\uc5b4\uc11c \uc5ec\ub7ec \uc194\ub8e8\uc158\uc744 \uac00\uc9c4 \ub77c\uc774\ube0c\ub7ec\ub9ac\uac00 \ub4f1\uc7a5\ud588\uc5c8\uc2b5\ub2c8\ub2e4. \uadf8\ub9ac\uace0 notifyDataSetChanged()\uac00 \ub4dc\ub514\uc5b4 \uc798 \uc791\ub3d9\ud569\ub2c8\ub2e4. \uc608\uc804\uc758 notifyDataSetChanged()\ub294 page\ub97c \uc7ac\uc0dd\uc131\ud558\uc9c0 \uc54a\uc558\uc2b5\ub2c8\ub2e4. \uac00\uc7a5 \uc77c\ubc18\uc801\uc778 \ud68c\ud53c\ubc29\ubc95\uc774 getItemPosition\uc744 \uc7ac\uc815\uc758\ud558\uc5ec\uc11c POSITION_NONE\uc744 \ubc18\ud658\ud558\ub294\uac83\uc774\uc600\uc8e0.<\/p>\n<h2>\uc758\uc874\uc131 \ucd94\uac00<\/h2>\n<pre class=\"lang:java decode:true\">implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha01'\r\n<\/pre>\n<h2>ViewPager2 \uad6c\ud604\ud574\ubcf4\uae30<\/h2>\n<p>\uc774\ubbf8 RecyclerView\uac00 \uce5c\uc219\ud558\ub2e4\uba74, ViewPager2\ub3c4 \uc27d\uac8c \uce5c\uc219\ud574\uc9c8 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\u00a0<br \/>\n\uc5b4\ub311\ud130\ubd80\ud130 \ub9cc\ub4e4\uc5b4\ubcf4\uc8e0.<\/p>\n<pre class=\"lang:java decode:true\">class CheesePagerAdapter(private val cheeseStrings: Array&lt;String&gt;) : RecyclerView.Adapter&lt;CheeseViewHolder&gt;() {\r\n    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CheeseViewHolder {\r\n        return CheeseViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.cheese_list_item, parent, false))\r\n    }\r\n\r\n    override fun onBindViewHolder(holder: CheeseViewHolder, position: Int) {\r\n        holder.cheeseName.text = cheeseStrings[position]\r\n    }\r\n\r\n    override fun getItemCount() = cheeseStrings.size\r\n}<\/pre>\n<p>\ub2f9\uc5f0\ud788 \ubdf0\ud640\ub354\ub3c4 \uc788\uc5b4\uc57c\uaca0\uc8e0<\/p>\n<pre class=\"lang:java decode:true \">class CheeseViewHolder(view: View) : RecyclerView.ViewHolder(view) {\r\n\r\n    val cheeseName: TextView = view.findViewById(R.id.cheese_name)\r\n}<\/pre>\n<p>\uc790 \uc774\uc81c \uc5b4\ub311\ud130\uc758 \uc778\uc2a4\ud134\uc2a4\ub97c ViewPager2\uc5d0 \uaf42\uc544\uc8fc\uae30\ub9cc \ud558\uba74 \uc900\ube44\ub294 \ub05d\ub0a9\ub2c8\ub2e4. \ubcc4\ub3c4\uc758 \ub808\uc774\uc544\uc6c3 \ub9e4\ub2c8\uc800\ub97c \ub9cc\ub4e4\uc5b4\uc904 \ud544\uc694\ub294 \uc5c6\uc2b5\ub2c8\ub2e4.\u00a0<\/p>\n<pre class=\"lang:java decode:true \">viewPager.adapter = CheesePagerAdapter(Cheeses.CheeseStrings)<\/pre>\n<div style=\"width: 750px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]--><br \/>\n<video class=\"wp-video-shortcode\" id=\"video-1037-1\" width=\"750\" height=\"1333\" loop=\"1\" autoplay=\"1\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/02\/ezgif.com-gif-to-mp4.mp4?_=1\" \/><a href=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/02\/ezgif.com-gif-to-mp4.mp4\">https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/02\/ezgif.com-gif-to-mp4.mp4<\/a><\/video><\/div>\n<p>&nbsp;<\/p>\n<p>\uc138\ub85c\ubaa8\ub4dc\ub3c4 \ub418\ub294\uc9c0 \ud655\uc778\ud574\ubcf4\uc8e0.<\/p>\n<pre class=\"lang:java decode:true \">viewPager.orientation = ViewPager2.ORIENTATION_VERTICAL\r\n<\/pre>\n<p>&nbsp;<\/p>\n<div style=\"width: 750px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-1037-2\" width=\"750\" height=\"1333\" loop=\"1\" autoplay=\"1\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/02\/ezgif.com-gif-to-mp4-1.mp4?_=2\" \/><a href=\"https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/02\/ezgif.com-gif-to-mp4-1.mp4\">https:\/\/www.charlezz.com\/wordpress\/wp-content\/uploads\/2019\/02\/ezgif.com-gif-to-mp4-1.mp4<\/a><\/video><\/div>\n<h2>ViewPager2.class<\/h2>\n<pre class=\"lang:java decode:true\">public class ViewPager2 extends ViewGroup {\r\n    ...\r\n    private void initialize(Context context, AttributeSet attrs) {\r\n        mRecyclerView = new RecyclerView(context) {\r\n            ...\r\n        };\r\n        mRecyclerView.setId(ViewCompat.generateViewId());\r\n\r\n        mLayoutManager = new LinearLayoutManager(context);\r\n        mRecyclerView.setLayoutManager(mLayoutManager);\r\n        setOrientation(context, attrs);\r\n\r\n        mRecyclerView.setLayoutParams(\r\n                new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));\r\n        mRecyclerView.addOnChildAttachStateChangeListener(enforceChildFillListener());\r\n        new PagerSnapHelper().attachToRecyclerView(mRecyclerView);\r\n        ...\r\n    }\r\n    ...\r\n    public final void setAdapter(@Nullable Adapter adapter) {\r\n        mRecyclerView.setAdapter(adapter);\r\n    }\r\n\r\n   ...\r\n}<\/pre>\n<p><a href=\"https:\/\/android.googlesource.com\/platform\/frameworks\/support\/+\/androidx-master-dev\/viewpager2\/src\/main\/java\/androidx\/viewpager2\/widget\/ViewPager2.java\">\uc804\uccb4\ucf54\ub4dc<\/a>\ub97c \ud655\uc778\ud560 \uc21c \uc5c6\uace0 \uac04\ub2e8\ud788 \ucd08\uae30\ud654 \ud558\ub294 \ucf54\ub4dc\ub9cc \ubcf4\ub3c4\ub85d \ud558\uaca0\uc2b5\ub2c8\ub2e4. ViewPager2\ub294 RecyclerView\uc640 LayoutManager\ub97c \ub0b4\ubd80\uc5d0\uc11c \ud488\uace0 \uc788\uae30 \ub54c\ubb38\uc5d0, \uc0ac\uc2e4 \uc77c\ubc18\uc801\uc73c\ub85c \uc6b0\ub9ac\uac00 \uc4f0\ub294 RecyclerView\uc640 \ub9e4\uc6b0 \ud761\uc0ac\ud569\ub2c8\ub2e4. \uae30\uc874 ViewPager\ucc98\ub7fc \ud398\uc774\uc9c0\ubcc4\ub85c \uc2a4\ub0c5\ub418\ub294 \uae30\ub2a5\uc744 \ucd94\uac00\ud558\uae30\uc704\ud574 PageSnapHelper\ub3c4 \ubcf4\uc785\ub2c8\ub2e4.<\/p>\n<p><del>\uae00\uc744 \uc4f0\ub2e4\ubcf4\ub2c8 \uadf8\ub0e5 RecyclerView\ub97c \ub9ac\ubdf0\ud558\ub294 \ub290\ub08c\uc774 \ub4ed\ub2c8\ub2e4.<\/del><\/p>\n<h1>Summary<\/h1>\n<p>ViewPager2\ub294 \uae30\uc874 ViewPager\ub97c \ub300\uccb4 \ud560\uc218 \uc788\ub294 \ud6cc\ub96d\ud55c \ub300\uccb4\uc81c\uac00 \ub420\uac83\uc73c\ub85c \uae30\ub300\ub429\ub2c8\ub2e4. RecyclerView\ub97c \uac00\uc9c0\uace0 \uc788\uc73c\ubbc0\ub85c, RecyclerView\uac00 \uac00\uc9c0\uace0 \uc788\ub294 \ubaa8\ub4e0 \uae30\ub2a5\uc744 \uc4f8 \uc218 \uc788\uaca0\uc8e0. notifyItemChanged(), notifyItemInserted() \uba54\uc18c\ub4dc \uadf8\ub9ac\uace0 DiffUtil\ub3c4 \uc4f8\uc218 \uc788\uaca0\ub124\uc694. ItemDecoration\uc774\ub77c\ub358\uac00 PageTransformer \uae4c\uc9c0 \uc801\uc6a9\ud55c\ub2e4\uba74 \ub354 \ud6cc\ub96d\ud55c \uc571\uc744 \ub9cc\ub4e4\uc218 \uc788\uc744 \uac83\uc73c\ub85c \uae30\ub300\ub429\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Released ViewPager2! \uad6c\uae00\uc774 ViewPager\ub97c 2011\ub144\uc5d0 \ub9b4\ub9ac\uc988\ud55c \uc774\ud6c4\ub85c \uc0c8\ub85c\uc6b4 \ubc84\uc804\uc778 ViewPager2(\uc54c\ud30c\ubc84\uc804)\ub97c \ub9b4\ub9ac\uc988 \ud588\uc2b5\ub2c8\ub2e4.\u00a0 \ub9ce\uc740 \uac1c\ubc1c\uc790\ub4e4\uc774 \ud398\uc774\uc9c0\ub2e8\uc704\uc758 \uae30\ub2a5\uc744 \uad6c\ud604\ud558\uae30 \uc704\ud574 \uc774 \ucef4\ud3ec\ub10c\ud2b8\ub97c \uc0ac\uc6a9\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.\u00a0 \ub9ce\uc740 \uac1c\ubc1c\uc790\ub4e4\uc774 \uc0ac\uc6a9\ud55c\ub2e4\uace0 \ud574\uc11c \uc0ac\uc6a9\ud558\uae30 \uc26c\uc6b4 \ucef4\ud3ec\ub10c\ud2b8\ub294 \uc544\ub2d9\ub2c8\ub2e4. ViewPager\ub97c \ub9cc\ub4e4\uae30\uc704\ud574\uc11c\ub294 Adapter\ub3c4 \uad6c\ud604\ud574\uc57c\ud558\uba70, \uc5b4\ub5a4 \uc5b4\ub311\ud130\ub97c \uad6c\ud604\ud574\uc57c\ud560\uc9c0 \ud56d\uc0c1 \uace0\ubbfc\ud558\uac8c \ub429\ub2c8\ub2e4. FragmentPagerAdapter\ub97c \uc368\uc57c\ud560\uc9c0 \ub610\ub294\u00a0 FragmentStatePagerAdapter\uc368\uc57c\ud558\ub294\uc9c0 \ub9d0\uc774\uc8e0. \uadf8\ub9ac\uace0 Fragment\ub97c \uaf2d \uc0ac\uc6a9\ud574\uc57c\ud558\ub294\uc9c0\ub3c4&#8230; New [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[16],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/1037"}],"collection":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1037"}],"version-history":[{"count":8,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/1037\/revisions"}],"predecessor-version":[{"id":1274,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/1037\/revisions\/1274"}],"wp:attachment":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}