{"id":314995,"date":"2020-12-16T21:00:25","date_gmt":"2020-12-16T21:00:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=314995"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=314995","title":{"rendered":"\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 ItemDecoration \u0434\u043b\u044f RecyclerView"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p><strong>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430:<\/strong><\/p>\n<blockquote>\n<p>\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 GIF-\u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0441 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u0434\u0430 (\u0442. \u0435. \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442). \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043c\u043d\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u044e, \u0442. \u043a. \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043e\u0442 \u0425\u0430\u0431\u0440\u0430, \u0430 \u043e\u043d \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0438\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \ud83d\ude42 \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0439, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/p>\n<\/blockquote>\n<p>\u041a\u0430\u043a-\u0442\u043e \u0440\u0430\u0437 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 ItemDecoration, \u0438 \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0432 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435. \u043f\u043e\u0447\u0442\u0438 \u043d\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430.<\/p>\n<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d19\/a56\/766\/d19a56766ca60cfd6d88aaed0963bdc0\" width=\"600\" height=\"602\"><figcaption><\/figcaption><\/figure>\n<ol>\n<li>\n<p><strong>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 ItemDecoration<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 ItemDecoration<\/strong><\/p>\n<ol>\n<li>\n<p><code>ItemDecoration<\/code>&nbsp;\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p><code>ItemDecoration<\/code>&nbsp;\u0431\u0435\u0437 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430<\/p>\n<\/li>\n<li>\n<p><code>ItemDecoration<\/code>&nbsp;\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0442\u0438\u043f\u0435 View<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>1. \u041f\u0440\u043e\u0441\u0442\u043e\u0439 ItemDecoration : DividerItemDecoration<\/h2>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>DividerItemDecoration<\/code>&nbsp;\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 Android-\u043e\u043c.<\/p>\n<pre><code class=\"java\">DividerItemDecoration(Context context, int orientation)<\/code><\/pre>\n<blockquote>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c <strong><em>RecyclerView.ItemDecoration<\/em><\/strong><em>&nbsp;<\/em>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 LinearLayoutManager<em>.<\/em><\/p>\n<\/p>\n<p><strong><em>@param context&nbsp;<\/em><\/strong><em>[\u2026]<\/em><strong><em>&nbsp;<\/em><\/strong>\u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c.<\/p>\n<p><strong><em>@param orientation&nbsp;<\/em><\/strong><em>[\u2026]<\/em><strong><em>&nbsp;<\/em><\/strong>\u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c<em> #HORIZONTAL \u0438\u043b\u0438 #VERTICAL.<\/em><\/p>\n<\/blockquote>\n<p>\u0427\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0442\u0430\u043a \u044d\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c drawable-\u0440\u0435\u0441\u0443\u0440\u0441, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"java\">recyclerView.addItemDecoration(     DividerItemDecoration(context, LinearLayoutManager.HORIZONTAL)         .apply { setDrawable(myDrawable) } )<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/162\/ba5\/74b\/162ba574bd451b265353292fd68e7e43\" alt=\"\u041f\u0440\u043e\u0441\u0442\u043e\u0439 DividerItemDecoration\" title=\"\u041f\u0440\u043e\u0441\u0442\u043e\u0439 DividerItemDecoration\" width=\"600\" height=\"208\"><figcaption>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 DividerItemDecoration<\/figcaption><\/figure>\n<\/p>\n<p><strong>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/strong><\/p>\n<ul>\n<li>\n<p>4 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c Android<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e: \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f &#8212; \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f \u043f\u0443\u0441\u0442\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e\u043c \u0438\u043b\u0438 \u043b\u0438\u043d\u0438\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 &#171;\u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439&#187; \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u043e\u0439 (\u0438\u043b\u0438 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0435\u0439): \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043c\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0445\u043e\u0442\u0438\u043c.<\/p>\n<\/li>\n<\/ul>\n<h2>2. Custom ItemDecoration<\/h2>\n<\/p>\n<p>\u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u0435\u0449\u0435\u0439 \u043c\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c RecyclerView.ItemDecoration. <\/p>\n<p>\u041d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b 3 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p><code>getItemOffsets<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>onDraw<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>onDrawOver<\/code> \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0438 onDraw, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0441\u0430\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043d.<\/p>\n<\/li>\n<\/ul>\n<p>? C\u043c. \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e: <code>getItemOffsets<\/code>, <code>onDraw<\/code>, <code>onDrawOver<\/code>.<\/p>\n<p>? \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0441 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0439.<\/p>\n<h3>2.1. Decoration &nbsp;\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u043a\u0440\u0430\u0441\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441 \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7e6\/f45\/0a5\/7e6f450a5f30c8e354ce9584288f8317\" alt=\"\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 ItemDecoration \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 View\" title=\"\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 ItemDecoration \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 View\" width=\"600\" height=\"239\"><figcaption>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 ItemDecoration \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 View<\/figcaption><\/figure>\n<p>\u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0437\u0434\u0435\u0441\u044c \u0437\u0434\u0435\u0441\u044c <code>parent.getChildAdapterPosition (view)<\/code><\/p>\n<blockquote>\n<p>\u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 View \u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435. \u0421\u043c. <a href=\"https:\/\/developer.android.com\/reference\/kotlin\/androidx\/recyclerview\/widget\/RecyclerView#getchildadapterposition\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u043b\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/a>.<\/p>\n<p>\u26a0\ufe0f \u041d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439 (<code>parent.children<\/code> &#8212; \u044d\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435).<\/p>\n<p>\u26a0\ufe0f \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439 \u0441 <code>RecyclerView.NO_POSITION<\/code>, \u0442. \u043a.<code>getChildAdapterPosition<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c -1.<\/p>\n<\/blockquote>\n<pre><code class=\"java\">import android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View import androidx.core.view.children import androidx.recyclerview.widget.RecyclerView  class CustomPositionItemDecoration(private val dividerDrawable: Drawable) :     RecyclerView.ItemDecoration() {      override fun getItemOffsets(rect: Rect, view: View, parent: RecyclerView, s: RecyclerView.State) {         val position = parent.getChildAdapterPosition(view)             .let { if (it == RecyclerView.NO_POSITION) return else it }         rect.right =             if (position % 2 == 0) 2             else dividerDrawable.intrinsicWidth     }      override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {         parent.children             .forEach { view -&gt;                 val position = parent.getChildAdapterPosition(view)                     .let { if (it == RecyclerView.NO_POSITION) return else it }                 if (position % 2 != 0) {                     val left = view.right                     val top = parent.paddingTop                     val right = left + dividerDrawable.intrinsicWidth                     val bottom = top + dividerDrawable.intrinsicHeight - parent.paddingBottom                     dividerDrawable.bounds = Rect(left, top, right, bottom)                     dividerDrawable.draw(canvas)                 }             }     }  }<\/code><\/pre>\n<h3>2.2. \u0423\u0434\u0430\u043b\u044f\u0435\u043c ItemDecoration \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043f\u0438\u0441\u043a\u0430<\/h3>\n<p>\u042d\u0442\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 StackOverflow, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0435. \u042d\u0442\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 <code>ItemDecoration<\/code>, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0ab\/7e7\/ed3\/0ab7e7ed3c1cf161920005247b37d2ec\" alt=\"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u0435 DividerItemDecoration, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\" title=\"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u0435 DividerItemDecoration, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\" width=\"600\" height=\"203\"><figcaption>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u0435 DividerItemDecoration, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/figcaption><\/figure>\n<\/p>\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0434\u043e\u0431\u0430\u0432\u0438\u0432&nbsp;<code>if (childAdapterPosition == adapter.itemCount-1)<\/code>.<\/p>\n<p>\u26a0\ufe0f \u041d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e&nbsp;<code>parent.adapter<\/code>&nbsp;\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <strong>null<\/strong>.<\/p>\n<pre><code class=\"java\">mport android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View import androidx.core.view.children import androidx.recyclerview.widget.RecyclerView  class DividerItemDecorationLastExcluded(private val dividerDrawable: Drawable) :     RecyclerView.ItemDecoration() {      private val dividerWidth = dividerDrawable.intrinsicWidth     private val dividerHeight = dividerDrawable.intrinsicHeight      override fun getItemOffsets(rect: Rect, v: View, parent: RecyclerView, s: RecyclerView.State) {         parent.adapter?.let { adapter -&gt;             val childAdapterPosition = parent.getChildAdapterPosition(v)                 .let { if (it == RecyclerView.NO_POSITION) return else it }             rect.right = \/\/ Add space\/\"padding\" on right side                 if (childAdapterPosition == adapter.itemCount - 1) 0    \/\/ No \"padding\"                 else dividerWidth                                       \/\/ Drawable width \"padding\"         }     }      override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {         parent.adapter?.let { adapter -&gt;             parent.children \/\/ Displayed children on screen                 .forEach { view -&gt;                     val childAdapterPosition = parent.getChildAdapterPosition(view)                         .let { if (it == RecyclerView.NO_POSITION) return else it }                     if (childAdapterPosition != adapter.itemCount - 1) {                         val left = view.right                         val top = parent.paddingTop                         val right = left + dividerWidth                         val bottom = top + dividerHeight - parent.paddingBottom                         dividerDrawable.bounds = Rect(left, top, right, bottom)                         dividerDrawable.draw(canvas)                     }                 }         }     } }<\/code><\/pre>\n<p>? \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0432\u0430\u043c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043c\u0435\u0436\u0434\u0443 \u0432\u0430\u0448\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e). \u041d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>onDraw<\/code>, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 <strong>Rect<\/strong> \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <strong>getItemsOffsets<\/strong>.<\/p>\n<pre><code class=\"java\">import android.graphics.Rect import android.view.View import androidx.recyclerview.widget.RecyclerView  class SimpleDividerItemDecorationLastExcluded(private val spacing: Int) :     RecyclerView.ItemDecoration() {      override fun getItemOffsets(         rect: Rect,         view: View,         parent: RecyclerView,         s: RecyclerView.State     ) {         parent.adapter?.let { adapter -&gt;             rect.right = when (parent.getChildAdapterPosition(view)) {                 RecyclerView.NO_POSITION,                 adapter.itemCount - 1 -&gt; 0                 else -&gt; spacing             }         }     } }<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b42\/9d9\/7b7\/b429d97b7ad427650733d354e6fcae3d\" alt=\"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 DividerItemDecoration, \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e\" title=\"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 DividerItemDecoration, \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e\" width=\"600\" height=\"204\"><figcaption>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 DividerItemDecoration, \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e<\/figcaption><\/figure>\n<h3>2.3. \u041e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0438\u043f\u0430 View<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 2 \u0442\u0438\u043f\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u043d\u044b\u043c \u0438 \u0441\u0435\u0440\u044b\u043c. \u041c\u044b \u043e\u0444\u043e\u0440\u043c\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u0438\u043d\u0438\u043c\u0438 \u0438 \u043a\u0440\u0430\u0441\u043d\u044b\u043c\u0438 <code>Drawable<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 <code>View<\/code> (\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 <code>Adapter-\u0435<\/code>).<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eda\/c26\/729\/edac26729dd25ef64a226af098523874\" alt=\"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 ItemDecoration  \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 View\" title=\"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 ItemDecoration  \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 View\" width=\"600\" height=\"254\"><figcaption>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 ItemDecoration  \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 View<\/figcaption><\/figure>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u043a\u043e\u0434\u0430 \u0437\u0434\u0435\u0441\u044c \u0437\u0434\u0435\u0441\u044c &#8212; <code>adapter.getItemViewType(childAdapterPosition)<\/code>. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>getItemViewType<\/code> \u0432 \u043d\u0430\u0448\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435.<\/p>\n<blockquote>\n<p>\u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0438\u043f View \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f View. [\u2026] \u041f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435 \u043d\u0430\u0434 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c id-\u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0434\u043b\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 View.<\/p>\n<\/p>\n<p>\u0421\u043c. <a href=\"https:\/\/developer.android.com\/reference\/android\/widget\/Adapter#getItemViewType(int)\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/a> <code>getItemViewType<\/code>.<\/p>\n<\/blockquote>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0438\u043f \u0432\u0430\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0438 \u0443\u043a\u0440\u0430\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0436\u0435\u043b\u0430\u043d\u0438\u044e ?.<\/p>\n<pre><code class=\"java\">import android.content.Context import android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View import androidx.core.content.ContextCompat import androidx.core.view.children import androidx.recyclerview.widget.RecyclerView  class CustomItemDecoration(context: Context) : RecyclerView.ItemDecoration() {      private val decorationRed = ContextCompat.getDrawable(context, R.drawable.item_decoration_red)!!     private val decorationBlue = ContextCompat.getDrawable(context, R.drawable.item_decoration_blue)!!      override fun getItemOffsets(rect: Rect, view: View, parent: RecyclerView, s: RecyclerView.State) {         parent.adapter?.let { adapter -&gt;             val childAdapterPosition = parent.getChildAdapterPosition(view)                 .let { if (it == RecyclerView.NO_POSITION) return else it }              rect.right = when (adapter.getItemViewType(childAdapterPosition)) {                 CustomAdapter.EVEN_ITEM_ID -&gt; decorationRed.intrinsicWidth                 CustomAdapter.ODD_ITEM_ID -&gt; decorationBlue.intrinsicWidth                 else -&gt; 0             }         }     }      override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {         parent.adapter?.let { adapter -&gt;             parent.children                 .forEach { view -&gt;                     val childAdapterPosition = parent.getChildAdapterPosition(view)                         .let { if (it == RecyclerView.NO_POSITION) return else it }                      when (adapter.getItemViewType(childAdapterPosition)) {                         CustomAdapter.EVEN_ITEM_ID -&gt; decorationRed.drawSeparator(view, parent, canvas)                         CustomAdapter.ODD_ITEM_ID -&gt; decorationBlue.drawSeparator(view, parent, canvas)                         else -&gt; Unit                     }                 }         }     }      private fun Drawable.drawSeparator(view: View, parent: RecyclerView, canvas: Canvas) =         apply {             val left = view.right             val top = parent.paddingTop             val right = left + intrinsicWidth             val bottom = top + intrinsicHeight - parent.paddingBottom             bounds = Rect(left, top, right, bottom)             draw(canvas)         }  }<\/code><\/pre>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u043c\u043e\u0451\u043c <a href=\"https:\/\/github.com\/NicolasDuponchel\" rel=\"noopener noreferrer nofollow\">GitHub \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/532552\/\"> https:\/\/habr.com\/ru\/post\/532552\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p><strong>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430:<\/strong><\/p>\n<blockquote>\n<p>\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 GIF-\u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0441 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043e\u0434\u0430 (\u0442. \u0435. \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442). \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043c\u043d\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432 \u0441\u0442\u0430\u0442\u044c\u044e, \u0442. \u043a. \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 \u043e\u0442 \u0425\u0430\u0431\u0440\u0430, \u0430 \u043e\u043d \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0438\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \ud83d\ude42 \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0439, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/p>\n<\/blockquote>\n<p>\u041a\u0430\u043a-\u0442\u043e \u0440\u0430\u0437 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 ItemDecoration, \u0438 \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0432 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435. \u043f\u043e\u0447\u0442\u0438 \u043d\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430.<\/p>\n<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<ol>\n<li>\n<p><strong>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 ItemDecoration<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 ItemDecoration<\/strong><\/p>\n<ol>\n<li>\n<p><code>ItemDecoration<\/code>&nbsp;\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p><code>ItemDecoration<\/code>&nbsp;\u0431\u0435\u0437 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430<\/p>\n<\/li>\n<li>\n<p><code>ItemDecoration<\/code>&nbsp;\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0442\u0438\u043f\u0435 View<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>1. \u041f\u0440\u043e\u0441\u0442\u043e\u0439 ItemDecoration : DividerItemDecoration<\/h2>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>DividerItemDecoration<\/code>&nbsp;\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 Android-\u043e\u043c.<\/p>\n<pre><code class=\"java\">DividerItemDecoration(Context context, int orientation)<\/code><\/pre>\n<blockquote>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c <strong><em>RecyclerView.ItemDecoration<\/em><\/strong><em>&nbsp;<\/em>\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 LinearLayoutManager<em>.<\/em><\/p>\n<\/p>\n<p><strong><em>@param context&nbsp;<\/em><\/strong><em>[\u2026]<\/em><strong><em>&nbsp;<\/em><\/strong>\u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c.<\/p>\n<p><strong><em>@param orientation&nbsp;<\/em><\/strong><em>[\u2026]<\/em><strong><em>&nbsp;<\/em><\/strong>\u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c<em> #HORIZONTAL \u0438\u043b\u0438 #VERTICAL.<\/em><\/p>\n<\/blockquote>\n<p>\u0427\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0442\u0430\u043a \u044d\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0443\u044e \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c drawable-\u0440\u0435\u0441\u0443\u0440\u0441, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"java\">recyclerView.addItemDecoration(     DividerItemDecoration(context, LinearLayoutManager.HORIZONTAL)         .apply { setDrawable(myDrawable) } )<\/code><\/pre>\n<figure class=\"full-width\"><figcaption>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 DividerItemDecoration<\/figcaption><\/figure>\n<\/p>\n<p><strong>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/strong><\/p>\n<ul>\n<li>\n<p>4 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c Android<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0441\u0442 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e: \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f &#8212; \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f \u043f\u0443\u0441\u0442\u044b\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e\u043c \u0438\u043b\u0438 \u043b\u0438\u043d\u0438\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 &#171;\u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439&#187; \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u043e\u0439 (\u0438\u043b\u0438 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0435\u0439): \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043c\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0445\u043e\u0442\u0438\u043c.<\/p>\n<\/li>\n<\/ul>\n<h2>2. Custom ItemDecoration<\/h2>\n<\/p>\n<p>\u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u0435\u0449\u0435\u0439 \u043c\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c RecyclerView.ItemDecoration. <\/p>\n<p>\u041d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b 3 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p><code>getItemOffsets<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>onDraw<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><code>onDrawOver<\/code> \u0442\u043e \u0436\u0435, \u0447\u0442\u043e \u0438 onDraw, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0441\u0430\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043d.<\/p>\n<\/li>\n<\/ul>\n<p>? C\u043c. \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e: <code>getItemOffsets<\/code>, <code>onDraw<\/code>, <code>onDrawOver<\/code>.<\/p>\n<p>? \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0441 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0439.<\/p>\n<h3>2.1. Decoration &nbsp;\u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440: \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u043a\u0440\u0430\u0441\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441 \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435.<\/p>\n<figure class=\"full-width\"><figcaption>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 ItemDecoration \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 View<\/figcaption><\/figure>\n<p>\u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0437\u0434\u0435\u0441\u044c \u0437\u0434\u0435\u0441\u044c <code>parent.getChildAdapterPosition (view)<\/code><\/p>\n<blockquote>\n<p>\u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 View \u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435. \u0421\u043c. <a href=\"https:\/\/developer.android.com\/reference\/kotlin\/androidx\/recyclerview\/widget\/RecyclerView#getchildadapterposition\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u043b\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/a>.<\/p>\n<p>\u26a0\ufe0f \u041d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439 (<code>parent.children<\/code> &#8212; \u044d\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435).<\/p>\n<p>\u26a0\ufe0f \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439 \u0441 <code>RecyclerView.NO_POSITION<\/code>, \u0442. \u043a.<code>getChildAdapterPosition<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c -1.<\/p>\n<\/blockquote>\n<pre><code class=\"java\">import android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View import androidx.core.view.children import androidx.recyclerview.widget.RecyclerView  class CustomPositionItemDecoration(private val dividerDrawable: Drawable) :     RecyclerView.ItemDecoration() {      override fun getItemOffsets(rect: Rect, view: View, parent: RecyclerView, s: RecyclerView.State) {         val position = parent.getChildAdapterPosition(view)             .let { if (it == RecyclerView.NO_POSITION) return else it }         rect.right =             if (position % 2 == 0) 2             else dividerDrawable.intrinsicWidth     }      override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {         parent.children             .forEach { view -&gt;                 val position = parent.getChildAdapterPosition(view)                     .let { if (it == RecyclerView.NO_POSITION) return else it }                 if (position % 2 != 0) {                     val left = view.right                     val top = parent.paddingTop                     val right = left + dividerDrawable.intrinsicWidth                     val bottom = top + dividerDrawable.intrinsicHeight - parent.paddingBottom                     dividerDrawable.bounds = Rect(left, top, right, bottom)                     dividerDrawable.draw(canvas)                 }             }     }  }<\/code><\/pre>\n<h3>2.2. \u0423\u0434\u0430\u043b\u044f\u0435\u043c ItemDecoration \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043f\u0438\u0441\u043a\u0430<\/h3>\n<p>\u042d\u0442\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 StackOverflow, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0435. \u042d\u0442\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 <code>ItemDecoration<\/code>, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435.<\/p>\n<figure class=\"full-width\"><figcaption>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0435 \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u0435 DividerItemDecoration, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/figcaption><\/figure>\n<\/p>\n<p>\u0418\u0441\u043a\u043b\u044e\u0447\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0434\u043e\u0431\u0430\u0432\u0438\u0432&nbsp;<code>if (childAdapterPosition == adapter.itemCount-1)<\/code>.<\/p>\n<p>\u26a0\ufe0f \u041d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e&nbsp;<code>parent.adapter<\/code>&nbsp;\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <strong>null<\/strong>.<\/p>\n<pre><code class=\"java\">mport android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View import androidx.core.view.children import androidx.recyclerview.widget.RecyclerView  class DividerItemDecorationLastExcluded(private val dividerDrawable: Drawable) :     RecyclerView.ItemDecoration() {      private val dividerWidth = dividerDrawable.intrinsicWidth     private val dividerHeight = dividerDrawable.intrinsicHeight      override fun getItemOffsets(rect: Rect, v: View, parent: RecyclerView, s: RecyclerView.State) {         parent.adapter?.let { adapter -&gt;             val childAdapterPosition = parent.getChildAdapterPosition(v)                 .let { if (it == RecyclerView.NO_POSITION) return else it }             rect.right = \/\/ Add space\/\"padding\" on right side                 if (childAdapterPosition == adapter.itemCount - 1) 0    \/\/ No \"padding\"                 else dividerWidth                                       \/\/ Drawable width \"padding\"         }     }      override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {         parent.adapter?.let { adapter -&gt;             parent.children \/\/ Displayed children on screen                 .forEach { view -&gt;                     val childAdapterPosition = parent.getChildAdapterPosition(view)                         .let { if (it == RecyclerView.NO_POSITION) return else it }                     if (childAdapterPosition != adapter.itemCount - 1) {                         val left = view.right                         val top = parent.paddingTop                         val right = left + dividerWidth                         val bottom = top + dividerHeight - parent.paddingBottom                         dividerDrawable.bounds = Rect(left, top, right, bottom)                         dividerDrawable.draw(canvas)                     }                 }         }     } }<\/code><\/pre>\n<p>? \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0432\u0430\u043c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u043c\u0435\u0436\u0434\u0443 \u0432\u0430\u0448\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e). \u041d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>onDraw<\/code>, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 <strong>Rect<\/strong> \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <strong>getItemsOffsets<\/strong>.<\/p>\n<pre><code class=\"java\">import android.graphics.Rect import android.view.View import androidx.recyclerview.widget.RecyclerView  class SimpleDividerItemDecorationLastExcluded(private val spacing: Int) :     RecyclerView.ItemDecoration() {      override fun getItemOffsets(         rect: Rect,         view: View,         parent: RecyclerView,         s: RecyclerView.State     ) {         parent.adapter?.let { adapter -&gt;             rect.right = when (parent.getChildAdapterPosition(view)) {                 RecyclerView.NO_POSITION,                 adapter.itemCount - 1 -&gt; 0                 else -&gt; spacing             }         }     } }<\/code><\/pre>\n<figure class=\"full-width\"><figcaption>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 DividerItemDecoration, \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e<\/figcaption><\/figure>\n<h3>2.3. \u041e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0438\u043f\u0430 View<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 2 \u0442\u0438\u043f\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u043d\u044b\u043c \u0438 \u0441\u0435\u0440\u044b\u043c. \u041c\u044b \u043e\u0444\u043e\u0440\u043c\u043b\u044f\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u0438\u043d\u0438\u043c\u0438 \u0438 \u043a\u0440\u0430\u0441\u043d\u044b\u043c\u0438 <code>Drawable<\/code> \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 <code>View<\/code> (\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 <code>Adapter-\u0435<\/code>).<\/p>\n<figure class=\"full-width\"><figcaption>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 ItemDecoration  \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 View<\/figcaption><\/figure>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u043a\u043e\u0434\u0430 \u0437\u0434\u0435\u0441\u044c \u0437\u0434\u0435\u0441\u044c &#8212; <code>adapter.getItemViewType(childAdapterPosition)<\/code>. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>getItemViewType<\/code> \u0432 \u043d\u0430\u0448\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435.<\/p>\n<blockquote>\n<p>\u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0438\u043f View \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043f\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f View. [\u2026] \u041f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435 \u043d\u0430\u0434 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c id-\u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0434\u043b\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 View.<\/p>\n<\/p>\n<p>\u0421\u043c. <a href=\"https:\/\/developer.android.com\/reference\/android\/widget\/Adapter#getItemViewType(int)\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/a> <code>getItemViewType<\/code>.<\/p>\n<\/blockquote>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0438\u043f \u0432\u0430\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0438 \u0443\u043a\u0440\u0430\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0436\u0435\u043b\u0430\u043d\u0438\u044e ?.<\/p>\n<pre><code class=\"java\">import android.content.Context import android.graphics.Canvas import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View import androidx.core.content.ContextCompat import androidx.core.view.children import androidx.recyclerview.widget.RecyclerView  class CustomItemDecoration(context: Context) : RecyclerView.ItemDecoration() {      private val decorationRed = ContextCompat.getDrawable(context, R.drawable.item_decoration_red)!!     private val decorationBlue = ContextCompat.getDrawable(context, R.drawable.item_decoration_blue)!!      override fun getItemOffsets(rect: Rect, view: View, parent: RecyclerView, s: RecyclerView.State) {         parent.adapter?.let { adapter -&gt;             val childAdapterPosition = parent.getChildAdapterPosition(view)                 .let { if (it == RecyclerView.NO_POSITION) return else it }              rect.right = when (adapter.getItemViewType(childAdapterPosition)) {                 CustomAdapter.EVEN_ITEM_ID -&gt; decorationRed.intrinsicWidth                 CustomAdapter.ODD_ITEM_ID -&gt; decorationBlue.intrinsicWidth                 else -&gt; 0             }         }     }      override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {         parent.adapter?.let { adapter -&gt;             parent.children                 .forEach { view -&gt;                     val childAdapterPosition = parent.getChildAdapterPosition(view)                         .let { if (it == RecyclerView.NO_POSITION) return else it }                      when (adapter.getItemViewType(childAdapterPosition)) {                         <\/code><\/pre>\n<\/blockquote>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-314995","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/314995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=314995"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/314995\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=314995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=314995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=314995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}