Android layout - custom grid like layout - android

I am trying to find solution how to display images in 2 columns grid with first row need to be one element with two columns width.
Android customize first child of grid view
I found this. but I hope there is some better solution...

You can do it using FrameLayout. This kind of layout allow you to put more than one Layout or XML item above each other.
I recommend for you to use the FrameLayout as a parent layout. Inside it put two GridViews the first one will represent the first wide element. The second GridView will be the normal small elements.
Put into your first GridView with your specific XML properties (Double wider than the others) only one item. Put into your first GridView with your specific XML properties the rest of items.
When you are handling the actions or the filling of the second GridView neglect the first two positions (Position 0 and 1) then act normal for the other.
Here is a good example of the FrameLayout usage. And here is a simple example of the GridView usage. I hope it helps

Related

How to make evenly spaced Grid Layout with dynamically added square items

I would like to create a grid layout in which each item is taking as much space as possible (minus padding), but only as long as there are columns available (after that the next item would be inserted in the next row while keeping the size). Additionally, each item must be a square and is added dynamically.
Example layout with 10 items would be as follows:
I have tried to achieve this by setting weights, ratio constraints, overriding onMeasure - but I just can't get it to work. I would be happy with either a programmatic or an XML-based solution (as long as each item can be added programmatically). I would prefer the solution to be in Kotlin, but I would be happy with a Java-based one as well.
It's probably worth saying that each item in the grid layout is a layout (RelativeLayout as of now) to make inflating it and setting a layered background drawable programmatically easy.
I think you might be able achieve what you want with a different Layout
Have a look at https://github.com/google/flexbox-layout it has lots of methods to control how the cells grown or shrink and includes automatic or manual wrapping of cells.
Take a look at RecyclerView. You would need to pass GridLayoutManager. This tutorial may or may not help you. For square items, I suggest using CardView but it's not necessary. If you are targeting tablets as well as smartphones, check this out. And for dynamically adding new items, you should notify recyclerView's adapter. See this link. You can also extend RecyclerView or GridLayoutManager for more control over items.

How to define scrolling page with ImageView, TextView and ExtendableListView in same layout?

I have an Activity which is displaying an assortment of details about a particular widget. There is an image, a TextView for a description, some common stats in TextViews, and then a
variable sized list of categorised items, from 1 to hundreds.
Quick wireframe: http://i.imgur.com/Z4kY6Ky.png
My first assumption was to use a ScrollLayout containing all of these elements: ImageView, TextViews, ExtendableListView, which works only if I specify a height for the ExtendableListView. Since the height is variable this is not a solution. I'm also now aware it's not recommended to use ListViews inside ScrollLayouts.
So I'm stuck. Can anyone point me toward the best way to achieve this kind of layout?
Just put expandable list view as main component, and then put the header into the list. addHeaderView()

How to create a listview in android with 2 columns, each of them having items with different height?

I am quite new to android, so I apologize in advance for any inconveniences my question may provoke.
I would like to create a listview that looks exactly like this image.
http://www.flickr.com/photos/42311831#N07/10145401953/
The listview would have 2 columns, each having custom views with variable height (represented on the image with rectangular shapes in different colors).
Creating this with 2 different listviews would be quite an easy job.
My approach would be creating 2 listviews and making them kind of "listen" to each-others on-scroll event, and responding to it by scrolling themselves simultaneously. That would mean, if I scroll down one of those 2 listviews, the other one would respond as if I had scrolled it down as well.
I am not sure that this is the right solution, so I would like to ask if anyone has experience with creating a component like this one?
Thank you very much for your time,
Bojan
thaats not a listview its a gridview. a gridview that could be adjusted as per the content in each grids, you can create a simple gridview with fixed size in a same way a you create a linear layout, that is
define a gridview xml
define gridview row xml (this contains textviews, edittext, buttons etc) or from your image it can have colors like red,green,blue etc
you can set number of gridview as 1 while portrait mode and 2 while landscape mode to get what your image is looking
create above xml and in your activity you can inflate it just the way listviews are inflated.
or incase you need grids with uneven sizes check this library
http://www.androidviews.net/2013/01/pinterest-like-adapterview/
i hope im clear and you appreciate my effort :)

Need suggestions for dynamically creating views in android

I am going to start one app where my activity page will contain "n" grouped views. Grouped view means "collections of views (i.e. One group can have TextView+Button+ImageView)". So the page will have "n" number of such grouped views.
I need suggestions like what would be the best practice to implement this. I could think of below ones:
1) Should a ScrollView be used (Then I will have to create groups in runtime and place one under another)?
2) Or a ListView be used (Then how can I accommodate the height of each row as grouped views height may differ from each other?)
Or is there any other way I can go along with?
Appreciate the suggestions and any sample examples if have. Advance Thanks.
Both options would work, it really depends on your use case.
Place a vertical LinearLayout inside of a ScrollView and add your grouped-views to the LinearLayout. I would recommend this if you have a relatively small number of such views (not necessarily a fixed number, but small enough that you wouldn't have to scroll many "pages" to see them all). Make sure the ScrollView has android:layout_height="match_parent" and the LinearLayout has android:layout_height="wrap_content".
If the number of grouped-views is not small, you could use a ListView and make an Adapter for it. This lets you take advantage of ListView's automatic view recycling when items get scrolled off screen.
For either case, make an XML file for just the grouped-views. In code, you would get a LayoutInflater object (usually by calling Activity.getLayoutInflater()) and call inflate(R.layout.your_grouped_views, null). If using the LinearLayout, you would add it in code with one of the LinearLayout.addView(..) methods; if using the ListView, your adapter would return the whole thing from getView(...).
create one xml layout containing the constant elements of your group view.
in you main xml layout which will be the contentView of your application, put a ScrollView and a single LinearLayout.
then in the program inflate as many views of your group view as you want.
For your answer i want to give you referance of this website, on this website you can learn create dynamic view in android...

Grid or relative layout

I want to have a page in an app have multiple buttons (in grid fashion) I was wondering if it would be better to populate a grid layout with buttons or manually add buttons to a relative layout, or if it even matters. I want each button to do something different so if using a grid layout is better how would I do this. I know you need to have gridview.setOnItemClickListener but that would make each button do the same thing (I think). Any suggestions would be appreciated!
If you have a fixed number of buttons, use a RelayiveLayout or TableLayout. If you have an unknown number of buttons and want to be able to scroll through them, that's the time to use a GridView.

Categories

Resources