I currently have a recycler view that has a list of CardViews.
When I click on the card I want to be able to expand the card (change only the height). This is working fine by setting the new height to the card with an animation.
The problem is that when I click to expand the card, the width also shrinks to less than half the width of the screen. If I scroll the view away and come back the width is set correctly. Every time I try to expand the height, it expands to the right size but the width shrinks.
Is there something that I'm supposed to do to expand/collapse a card in a recycler view and not have this side effect of also resizing the card width?
I tried only setting the height in a valueAnimator and that works for the expansion.
I tried to set the width programmatically at the end of the animation to match parent but that has no effect.
for better solution pls share code with us, until that.
check your xml codes for any Wrap content value for width.
It will solve your issue.
Related
I have a problem with recyclerview items width:
i already looked through android docs and stack so i think, there is no solution to this problem.
i have an ordinary recyclerview with a horizontal gridlayout
sorry, but i dont have enough reputation to embed pictures
Picture of recyclerview
and i want the items of it being shown next to each other, but I want to make the width of the items depend on the width of the parent (in this case, the recyclerview width used in the other fragment).
I can show you what i want by using a fixed value (in this example 200dp)
Picture of the solution I want, but here a fixed value for width is used
However if my constraint of the item is set to "match parent" like here:
Picture constraint set to match parent
The result is, that the width of the items seen in the phone always depends of the width of the recyclerview. in my case its cut nearly in half:
recyclerview cut in half
also android studio only allows one view as a top level layout, so i cannot use a guideline that is set to any %
possible solution to that?
If you have width of recycler view (in pixel not dp), just divide it by number of items in a row, and in your adapter in "onBindViewHolder" method set item width. this solution is when all of your item has same width.
In addition for height of every item use WRAP_CONTENT.
I want to model my layout screen in the following 2 parts.
Basic Information related Linear layout with expandable view initially 20 % of screen height.
Bottom List view occupy Remaining Space.
But When the top view is expanded then i want to make it height upto 50 % and the bottom listview should start then after.
I have attached image for reference.
I have tried setting the layout_weight of top and bottom layout. But not able to find out exact solution. May be i am missing some points.
Let me know if you need more information from my end.
Thanks in Advance.
regards,
Rakesh
Try to remove the current weight from the top view and in the listview set android:layout_weight="1" and android:layout_height="0dp". This makes the ListView to take whatever height left in the screen.
Hi I am working on GridView which has header and footer.
In my case, the header's width should fill the screen width like below
But I am getting the header filled the grid items' width.
I have used the library.
What should I have to do to make the header's width match with screen width.
Note : The header only should filled the screen width not the grid items. And the grid items should have right and left margins.
Use the HFGridview
`https://github.com/SergeyBurish/HFGridView/tree/master/HFGridView
By this you will acheve waht you want with little bit customisation. I already implemented that. If you face any problem let me know I will share code with you.
I have 4 views in the same activity. I want to move each Imageview on touch in whole screen, but it allow me to move in its width height.
Each image view's layout height and width is wrap_content.
It works fine with one image view with fill_parent.
Its explained in this example.
I have a RelativeLayout filling the screen and a couple of ImageView positioned on it using LayoutParams margins. These ImageView are animated in different ways, and in one case I want an image to "fly in" to the screen from the right.
Unfortunately, if I set leftMargin for that ImageView greater than the width of the screen, it does not appear (or appears cropped if it partially visible at the start of animation).
I tried setting width and height of RelativeLayout to be bigger than screen size - it works, but only partially: if the image is positioned completely off-screen, it does not work, and if the image is partially visible, it is not cropped, but that works only for right and bottom sides.
So, my question is this: how to position several ImageViews on and off the screen so that I can animate them using Animation?
In the end, I used a trick: I combined AnimationDrawable and view animation. I did the following (assuming that the animation has to run T milliseconds):
Position that ImageView on-screen.
Set as its background an AnimationDrawable with following frames:
empty Drawable: 1ms,
normal Drawable: Tms.
Change view's animation to this:
jump to off-screen position (translation with duration=1ms),
do normal animation.
This is probably a good place to start looking for those who would use Fixpoint's solution.
Android — How to position View off-screen?