How to apply ItemDecoration from left and right side both to RecyclerView item?












5















I have been trying to achieve this for so long. What I want is to overlap the selected RecyclerView item from left and right as shown in the picture below.



enter image description hereenter image description here



I'm able to achieve left or right by ItemDecoration like below:



class OverlapDecoration(private val overlapWidth:Int) : RecyclerView.ItemDecoration() {
private val overLapValue = -40

val TAG = OverlapDecoration::class.java.simpleName

override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {

val itemPosition = parent.getChildAdapterPosition(view)

if (itemPosition == 0) {
return
} else {
outRect.set(overLapValue, 0, 0, 0)
}
}
}


I have achieved like below image so far.
enter image description here



I have already tried with CarouselLayoutManager but it not what I'm looking for.










share|improve this question

























  • setting itemDecoration(assigning overlap value to left and riht end at a time) to selctedItem and null to another will not help?

    – Vir Rajpurohit
    Aug 27 '18 at 12:56











  • @VirRajpurohit Already tried, not working!

    – Maddy
    Aug 27 '18 at 12:58











  • @Maddy Have you tried doing so with animations? Here is similar question stackoverflow.com/q/33269409/548208

    – Dhruv Mevada
    Aug 28 '18 at 4:59













  • @DhruvMevada Yes, It also gives the same result as ItemDecoration with the negative margin.

    – Maddy
    Aug 28 '18 at 5:10











  • Maybe this library can help you, although I've never used it myself - github.com/yarolegovich/DiscreteScrollView

    – Tohu
    Aug 29 '18 at 6:46
















5















I have been trying to achieve this for so long. What I want is to overlap the selected RecyclerView item from left and right as shown in the picture below.



enter image description hereenter image description here



I'm able to achieve left or right by ItemDecoration like below:



class OverlapDecoration(private val overlapWidth:Int) : RecyclerView.ItemDecoration() {
private val overLapValue = -40

val TAG = OverlapDecoration::class.java.simpleName

override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {

val itemPosition = parent.getChildAdapterPosition(view)

if (itemPosition == 0) {
return
} else {
outRect.set(overLapValue, 0, 0, 0)
}
}
}


I have achieved like below image so far.
enter image description here



I have already tried with CarouselLayoutManager but it not what I'm looking for.










share|improve this question

























  • setting itemDecoration(assigning overlap value to left and riht end at a time) to selctedItem and null to another will not help?

    – Vir Rajpurohit
    Aug 27 '18 at 12:56











  • @VirRajpurohit Already tried, not working!

    – Maddy
    Aug 27 '18 at 12:58











  • @Maddy Have you tried doing so with animations? Here is similar question stackoverflow.com/q/33269409/548208

    – Dhruv Mevada
    Aug 28 '18 at 4:59













  • @DhruvMevada Yes, It also gives the same result as ItemDecoration with the negative margin.

    – Maddy
    Aug 28 '18 at 5:10











  • Maybe this library can help you, although I've never used it myself - github.com/yarolegovich/DiscreteScrollView

    – Tohu
    Aug 29 '18 at 6:46














5












5








5








I have been trying to achieve this for so long. What I want is to overlap the selected RecyclerView item from left and right as shown in the picture below.



enter image description hereenter image description here



I'm able to achieve left or right by ItemDecoration like below:



class OverlapDecoration(private val overlapWidth:Int) : RecyclerView.ItemDecoration() {
private val overLapValue = -40

val TAG = OverlapDecoration::class.java.simpleName

override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {

val itemPosition = parent.getChildAdapterPosition(view)

if (itemPosition == 0) {
return
} else {
outRect.set(overLapValue, 0, 0, 0)
}
}
}


I have achieved like below image so far.
enter image description here



I have already tried with CarouselLayoutManager but it not what I'm looking for.










share|improve this question
















I have been trying to achieve this for so long. What I want is to overlap the selected RecyclerView item from left and right as shown in the picture below.



enter image description hereenter image description here



I'm able to achieve left or right by ItemDecoration like below:



class OverlapDecoration(private val overlapWidth:Int) : RecyclerView.ItemDecoration() {
private val overLapValue = -40

val TAG = OverlapDecoration::class.java.simpleName

override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {

val itemPosition = parent.getChildAdapterPosition(view)

if (itemPosition == 0) {
return
} else {
outRect.set(overLapValue, 0, 0, 0)
}
}
}


I have achieved like below image so far.
enter image description here



I have already tried with CarouselLayoutManager but it not what I'm looking for.







android android-recyclerview kotlin item-decoration






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 28 '18 at 5:42







Maddy

















asked Aug 27 '18 at 12:53









MaddyMaddy

1,66721532




1,66721532













  • setting itemDecoration(assigning overlap value to left and riht end at a time) to selctedItem and null to another will not help?

    – Vir Rajpurohit
    Aug 27 '18 at 12:56











  • @VirRajpurohit Already tried, not working!

    – Maddy
    Aug 27 '18 at 12:58











  • @Maddy Have you tried doing so with animations? Here is similar question stackoverflow.com/q/33269409/548208

    – Dhruv Mevada
    Aug 28 '18 at 4:59













  • @DhruvMevada Yes, It also gives the same result as ItemDecoration with the negative margin.

    – Maddy
    Aug 28 '18 at 5:10











  • Maybe this library can help you, although I've never used it myself - github.com/yarolegovich/DiscreteScrollView

    – Tohu
    Aug 29 '18 at 6:46



















  • setting itemDecoration(assigning overlap value to left and riht end at a time) to selctedItem and null to another will not help?

    – Vir Rajpurohit
    Aug 27 '18 at 12:56











  • @VirRajpurohit Already tried, not working!

    – Maddy
    Aug 27 '18 at 12:58











  • @Maddy Have you tried doing so with animations? Here is similar question stackoverflow.com/q/33269409/548208

    – Dhruv Mevada
    Aug 28 '18 at 4:59













  • @DhruvMevada Yes, It also gives the same result as ItemDecoration with the negative margin.

    – Maddy
    Aug 28 '18 at 5:10











  • Maybe this library can help you, although I've never used it myself - github.com/yarolegovich/DiscreteScrollView

    – Tohu
    Aug 29 '18 at 6:46

















setting itemDecoration(assigning overlap value to left and riht end at a time) to selctedItem and null to another will not help?

– Vir Rajpurohit
Aug 27 '18 at 12:56





setting itemDecoration(assigning overlap value to left and riht end at a time) to selctedItem and null to another will not help?

– Vir Rajpurohit
Aug 27 '18 at 12:56













@VirRajpurohit Already tried, not working!

– Maddy
Aug 27 '18 at 12:58





@VirRajpurohit Already tried, not working!

– Maddy
Aug 27 '18 at 12:58













@Maddy Have you tried doing so with animations? Here is similar question stackoverflow.com/q/33269409/548208

– Dhruv Mevada
Aug 28 '18 at 4:59







@Maddy Have you tried doing so with animations? Here is similar question stackoverflow.com/q/33269409/548208

– Dhruv Mevada
Aug 28 '18 at 4:59















@DhruvMevada Yes, It also gives the same result as ItemDecoration with the negative margin.

– Maddy
Aug 28 '18 at 5:10





@DhruvMevada Yes, It also gives the same result as ItemDecoration with the negative margin.

– Maddy
Aug 28 '18 at 5:10













Maybe this library can help you, although I've never used it myself - github.com/yarolegovich/DiscreteScrollView

– Tohu
Aug 29 '18 at 6:46





Maybe this library can help you, although I've never used it myself - github.com/yarolegovich/DiscreteScrollView

– Tohu
Aug 29 '18 at 6:46












1 Answer
1






active

oldest

votes


















0














To achieve the result you're looking for you need to take two steps:



First, to correct the decorator calculations:



if (itemPosition == 0) {
return
} else {
outRect.set(-1 * overLapValue, 0, overLapValue, 0) //Need left, AND right
}


Second, you need to actually add the shadow



And, one quick bit of cleanup for the class, you don't need the private val overLapValue.



Instead:



class OverlapDecoration(private val overlapWidth:Int = 40) : RecyclerView.ItemDecoration() {





share|improve this answer
























  • Thanks, but this is not what I want! It will only increase the space from the right item. Actually, I want the right item to go under the selected item in RecyclerView.

    – Maddy
    Nov 28 '18 at 4:54











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52039853%2fhow-to-apply-itemdecoration-from-left-and-right-side-both-to-recyclerview-item%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














To achieve the result you're looking for you need to take two steps:



First, to correct the decorator calculations:



if (itemPosition == 0) {
return
} else {
outRect.set(-1 * overLapValue, 0, overLapValue, 0) //Need left, AND right
}


Second, you need to actually add the shadow



And, one quick bit of cleanup for the class, you don't need the private val overLapValue.



Instead:



class OverlapDecoration(private val overlapWidth:Int = 40) : RecyclerView.ItemDecoration() {





share|improve this answer
























  • Thanks, but this is not what I want! It will only increase the space from the right item. Actually, I want the right item to go under the selected item in RecyclerView.

    – Maddy
    Nov 28 '18 at 4:54
















0














To achieve the result you're looking for you need to take two steps:



First, to correct the decorator calculations:



if (itemPosition == 0) {
return
} else {
outRect.set(-1 * overLapValue, 0, overLapValue, 0) //Need left, AND right
}


Second, you need to actually add the shadow



And, one quick bit of cleanup for the class, you don't need the private val overLapValue.



Instead:



class OverlapDecoration(private val overlapWidth:Int = 40) : RecyclerView.ItemDecoration() {





share|improve this answer
























  • Thanks, but this is not what I want! It will only increase the space from the right item. Actually, I want the right item to go under the selected item in RecyclerView.

    – Maddy
    Nov 28 '18 at 4:54














0












0








0







To achieve the result you're looking for you need to take two steps:



First, to correct the decorator calculations:



if (itemPosition == 0) {
return
} else {
outRect.set(-1 * overLapValue, 0, overLapValue, 0) //Need left, AND right
}


Second, you need to actually add the shadow



And, one quick bit of cleanup for the class, you don't need the private val overLapValue.



Instead:



class OverlapDecoration(private val overlapWidth:Int = 40) : RecyclerView.ItemDecoration() {





share|improve this answer













To achieve the result you're looking for you need to take two steps:



First, to correct the decorator calculations:



if (itemPosition == 0) {
return
} else {
outRect.set(-1 * overLapValue, 0, overLapValue, 0) //Need left, AND right
}


Second, you need to actually add the shadow



And, one quick bit of cleanup for the class, you don't need the private val overLapValue.



Instead:



class OverlapDecoration(private val overlapWidth:Int = 40) : RecyclerView.ItemDecoration() {






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 19:47









gtcompscientistgtcompscientist

613516




613516













  • Thanks, but this is not what I want! It will only increase the space from the right item. Actually, I want the right item to go under the selected item in RecyclerView.

    – Maddy
    Nov 28 '18 at 4:54



















  • Thanks, but this is not what I want! It will only increase the space from the right item. Actually, I want the right item to go under the selected item in RecyclerView.

    – Maddy
    Nov 28 '18 at 4:54

















Thanks, but this is not what I want! It will only increase the space from the right item. Actually, I want the right item to go under the selected item in RecyclerView.

– Maddy
Nov 28 '18 at 4:54





Thanks, but this is not what I want! It will only increase the space from the right item. Actually, I want the right item to go under the selected item in RecyclerView.

– Maddy
Nov 28 '18 at 4:54




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52039853%2fhow-to-apply-itemdecoration-from-left-and-right-side-both-to-recyclerview-item%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'