I need to layout a list of five items: 2 on top of the screen, 1 in the middle, 2 on the bottom (basically the green, red, black, orange, and purple squares below, and you can page horizontally through more of these pages):
I am trying to use a RecyclerView with a GridLayoutManager, however I am confused how to set the height of my list_item to be 1/3 the height of the screen (does this involve weight?).
Am I going about this right? Any direction appreciated; I am new to Android dev. Thanks.
Update: I made progress by nesting horizontal linear layouts within one encompassing vertical linear layout. Now I believe I need this to be the list_item, and fill a horizontally-paged list with these items (definitely want to use RecyclerView in conjunction with one of its layout managers.)
You can set span of gridlayout dynamically. Alternatively you can use Lucas Rochas TwoWayView lib which is equipped with different types of layout.
Related
My Idea is adding TextViews with rounded corners background to a horizontal LinearLayout, so if next one wouldn't fit - I will add TextView to another LinearLayout below.
Is there a way to do so? I know it sound like a custom view, but I would like not to bother as much - to adjust height, make click area calculations istead of simple clickListeners
Sounds like a recyclerview using a flexbox layout https://github.com/google/flexbox-layout with flexWrap turned on.
You could also use is in a static layout as well.
With flexWrap it does all the calculations to see if the "item" can fit on a line and if not starts a new line.
Many examples on the github page.
You could keep adding text views in linear layout while checking if newly added text view is outside of linear layout horizontal boundaries, if it is you could remove it from linear layout and add it in new one but I see no reason why you would want to do that.
I'm trying to achieve a design for recycler view in grid layout style. Any Input towards achieving it is very helpful.
I have to design for span size 2 only.
Design :
I tried to use GridLayoutManager with span size 2
If you mean that list should scroll horizontally and each next column should be following of previous one. I think you can done it by horizontal recycler view with items that contain two views and top space margin which increases sequentially.
Height of the RecyclerView should be calculated and set by last column in code.
I got the following recycler view, on the view item there are 5 checkboxes. How could I align the checkboxes inside the recycler view items with the TextView dates on the fragment..?
I tried using the same padding, but different dates got different sizes, as well as phones, so it doesnt display a correct alignment on all instances.. Is there a better way? I would appreciate any kind of indication, this is the last problem so I can publish the application.
You can achieve this in a simple way. Take all the textViews of your fragment inside a linear layout group. And keep the layout_weight similar. Thus the textViews will be equidistant.
Similarly, take the checkboxes in a LinearLayout view group. And keep the layout_weight similar. Thus the textViews will be equidistant.
Ps- check the padding and margin of the items, and adjust accordingly.
A single item in my RecyclerView consists of 3 charts but the last one turns out minuscule. How do I make them all appear their full size/total size bigger than 1 page?
To sum up: 1 item made up of 3 charts. Many such items in a RecyclerView.
Things that I've tried:
1. LinearLayout with equal weights.
2. RelativeLayouts with the heights explicitly mentioned.
Thing I'm trying to achieve:
What I have now:
I looked at MPAndroidChart's example and it uses ListView and not RecyclerView. Thanks in advance!
EDIT:
The answer was Wrapping the entire thing in a ScrollView.
I have a top section for the app which is mainly logo and stuff, and roughly the bottom half is supposed to be buttons.. In the outer container, i have a layout for the logo, and imageView to create a seperator line between the top and bottom and the bottom layout..
The issue is bottom layout has 2 linearlayouts (one of which is hidden initially) first one is just a spinner and the second one is 2 buttons..
I have achieved the "roughly 1/3 of space) by using layout_weights in the top and bottom linear layout (2 and 1 respectively) but when I hide the spinner and show the 2 buttons in the bottom layout in the code, the seperator line is pushed up.. I want it to stay in the same place (like be where it would be after the 2 buttons show up from the get-go so that it doesn't have to move)
I could probably just add some margin to the original one to match it but i feel like that will cause issues in the future on different devices.
How can I accomplish this feat?
I think you might be neglecting to set android:layout_height="0dp" on the LinearLayouts that you set android:layout_weight="1" on. If you do this it should fill the space like you want, and you can do layoutView.setVisibility(View.GONE) and layoutView.setVisibility(View.VISIBLE) to toggle the views.