Given this scenario :
image
I'm trying to position every child elements of the gridview such that it will have specific margin value with the gridview child element that is directly above the element, and I would like the margin value (the vertical spacing between each child) to be consistent in relation to the Gridview child element directly above it.
From the context of the image uploaded above, I want to minimize the spacing between each child elements vertically given the case that each Gridview element's height is variable and I intend to keep it this way.
I'm also using a custom adapter to supply the items for the GridView.
Is there any method/XML attribute in a GridView class I can use to perform this task or do I need to use a custom view and override from GridView to implement this feature?
Thanks in advance.
Well apparently GridView does not support this kind of implementation and I'll have to resort to using StaggeredGridLayoutManager.
Related
I'm aware of the DividerItemDecoration with regards to RecyclerViews although instead of a divider between every item I'm more interested in a divider whenever a certain attribute changes within my elements. For example, a list of transactions that hold the date by which they were posted - a divider would then display at each change in date in the list of transactions.
This is definitely possible but I'm just not sure to go about doing it. For example, in the Monzo application - it's the dates that separate the transaction lines.
Any help would be very much appreciated!
You would create a recycler view adapter with two viewholders. In the example of the Monzo app, you would create one ViewHolder for the purchase and the other for the date. Then in onCreateViewHolder you would inflate the correct type of viewholder for that item in that list.
One way you could do it is to add the divider to the ViewHolder layout, defaulting to View.INVISIBLE (or View.GONE if you want it to take up extra space when it's visible - like the divider is outside the list element instead of inside at the top edge)
Then in onBindViewHolder you could do a bit of logic to decide if the divider should be set to visible or not for that item - something that decides if it represents a date change, and make sure to check it's not the first item in the list too (don't want a random divider up there)
Is there any way to create a recycler where its first cell is twice as big as the other cells and all the other cells are in between the top and bottom of the first cell. Here is a drawing example because I can not explain it properly with words.
Create a POJO class for each different view types and pass the values to the POJO classes and add the POJO as the recycler view item.You can insert and render multiple view types inside a recycler view .
I'm using Retrofit2 to handle http comunication with backend. In response I'm getting data that i wish add to number of views specified in JSON file (size of array).
I want to create views like this but not the same. Basically picture and some text
I don't know what type of layout i should use. Grid, Relative, Linear, List? I also want to scroll this views.
You should maybe use recyclerview with cardview items.
You can set a scroll listener to the recyclerview , to define when you want to upload some new data .
I am trying to create a top bar for my app that shows the users level, coins. So i have an image view that displays the coin icon and a textview that displays the number of coins, if the number gets high it overlaps the image rather than pushing back the image and keeping everything aligned, is there a way to do that?
Without knowing your layout XML this is pure guesswork, but I'm assuming these two views are in a RelativeLayout. If so, add to one of them an attribute like this:
android:layout_toLeftOf="#id/otherViewId"
Options available are layout_toLeftOf layout_toRightOf layout_above and layout_below.
Post your layout XML and I'll update this with a better answer!
If you are using the relative layout then you can use the z-index attribute of views to manage the ordering.
I have implemented ExpandedListView. I have 2 questions for that
When I expand and scroll child item ,the group header also scroll ,is any way to keep that group header at top always even we scrolling child item list ?
Is any way to fit ExpandableListView (before child items comes) to phone screen , right now in bottom lot of blank space ?
For your first question:
no there is no why that you can fix the group view, if you want to fix group i would suggest you to make four list view on screen. where in a Linearlayout make 4 textview and 4 listview placed alternately so that they are fixed and if there is no child inside you can write some appropriate message saying there is nothing to display.
And i guess it solve your second question as well ?
1. When I expand and scroll child item ,the group header also scroll ,is any way to keep that group header at top always even we scrolling child item list ?
No, ExpandableListView's Header's (Parent) and Childs are connected to eachother You can not independently scroll the Child views besides scrolling parent views.
2. Is any way to fit ExpandableListView (before child items comes) to phone screen , right now in bottom lot of blank space ?
You can fit the ExpandableListView by setting its height and width to fixed but it will be always affected as and when you will add some data into it. Till then you can not fit it into the screen.