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.
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 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.
I have two scroll views in a vertical linear layout.
I want them to be relative to each other so that they fill the entire linear layout and compensate if one cant cover half the screen.
Lets call that scroll views TOP and BOT.
If the screen can display 4 rows and both scroll views have infinite rows, each scroll views should display 2 rows and be able to scroll down to se the rest rows.
If TOP has 1 and BOT infinite rows, BOT should be resized to 3/4 of the linear layout.
If TOP have infinite and Bot has 1 row TOP should still just display 2, i.e. it should never pass the linear layouts vertical center.
Here are some pictures for reference:
my setup with weight set to 0.5/0.5.
result of 0.5/0.5 weight. Notice the gray bar above the BOT title bar. This empty space should be filled by the BOT bar.
if Using fixed size or wrap content the TOP will push the Bot out of view.
How can I have them hugging each other and still set TOP to a maximal height?
Preferable in XML.
Its better to set the weight dynamically. Count the number of items in both views. Set the weight of each view according to the ratios of their number of items. You can refer set weight dynamically for setting weights at run time
I have a textview inside a grid layout and I want to change the size of grid cells according to the text area of the text view. If the word size is 5, then the grid size will be calculated accordingly. I am adding both the textview and the grid dynamically. I used the below code for this text area calculation,
text[i].setText(String.valueOf(finallist.get(i)));
text[i].measure(0, 0);
int widths = text[i].getMeasuredWidth();
params.width=widths;
text[i].setLayoutParams(params);
text[i].setTextSize(10);
where 'params' is the layout params for the textview. When I run this code, I am getting output as shown below.
Here I am getting extra spaces in between the grids no matter the textview size is wrapped. Instead I wanted the grid layout to occupy the area if it's available. I wanted the output like this,
I wanted equal spacing between the grids. How can I achieve this DYNAMICALLY .Also I am implementing drag and drop here. I am new to this. Please help. Thanks in advance.
Use StaggeredGridLayoutManager instead of normal GridLayout. A good example of Staggered Grid layout manager will be found here.
A LayoutManager that lays out children in a staggered grid formation. It supports horizontal & vertical layout as well as an ability to layout children in reverse. Staggered grids are likely to have gaps at the edges of the layout. To avoid these gaps, StaggeredGridLayoutManager can offset spans independently or move items between spans. You can control this behavior via setGapStrategy(int).
Hope it helps. Cheers!
you can use GridLayout.Spec as it has both rowSpec and columnSpec properties.Also try setAlignmentMode asit used for all of the alignments between the children of its container.
You should consider FlexboxLayout. Take a look at the readme at the GitHub project site. I think you will find that it will fit your needs. There is also a FlexboxLayoutManager for RecyclerView. This is all supported by Google.
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.