Dynamic linear layout logic for given below image - android

In my application, I need to design layout like given in a picture. The portion in red which have 3 views with green circle which will be dynamic. It can be 2 or 3 or 4 as I said it is dynamic. So please help to make logic of that or please suggest me how can I do that

Use the gridview or recyclerview with gridlayoutmanager with number of column 2.

Use two ListViews
segregate your data so that even numbers go in the left listview, and odds in the right listivew

I solved my problem by creating TableLayout dynamically with some logic with arraylist in adapter.If anybody needs it I can also guide.
GridView is not the right solution because under listview it is not scrollable dut to parent scroll property.

Related

How can I create an horizontal ListView in Android with fixed number of items?

I searched for a few hours over the internet but I didn't find any example or documentation explaining how to create an horizontal list view with fixed number of elements.
Basically, I would like to have, let's say 3 elements out of n(total number of elements) which are displayed on the screen without taking into consideration the size of the scree. The elements can be bigger or smaller proportionate to the screen but the number of visible elements should be the same, fixed. see the image.
How can I do that? Any hint is appreciated! Thank you!
You can use TwoWayWiew third party library (i dont really recommend this solution), or if you want to avoid to use lib for this, just use RecyclerView, and you can set HORIZONTAL param to layout manager.
I would not use a ListView for this, but a RecyclerView instead. Performance is better in a RecyclerView and I honestly find them easier to work with. You can allow for horizonatal scrolling via the LayoutManager for your RecyclerView.
If don't mind scrolling horizontally by 3 items you could use a ViewPager with each View containing a LinearLayout (orientation horizontal) with three of your elements that have a
android:layout_width="0dp" and an
andriod:layout_weight="1"
for even distribution.
When you "scroll" you would just animate the next "page" into the screen bringing in the next 3 elements.
This might not be the most elegant solution but I think it would behave the way you want.
use the linear layout with its orientation set as horizontal under the relative layout

Random children placement in gridlayout

Hey guys I have 26 buttons nicely arranged in a gridlayout but I am trying to achieve something. I want the buttons to shuffle and place themselves randomly in cell positions in the grid layout on a button click. AND none of them should be placed above another. Please can this be achieved? All suggestions are welcome. Thanks in advance.
GridLayout child positioning is solemnly bound to child index.
Which means to achieve random positioning all you need is randomly change child positions by using [ViewGroup.addView(View, int)](http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View, int)) and View.removeViewAt(int)
As for not placing above each other, the grid layout child distribution takes care of all this.
I finally did it. I just had to create a Random variable, remove each view and place them at a new random index

Android layout - custom grid like layout

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

Listview, Gridview or something else for single column of scrolling images

re: example http://www.youtube.com/watch?v=Ej--SFh963M
Similar to the above app, I am trying to create a scrolling list of images, like a Listview but with images only. (I also need to set it to fill a set height and width, say 85% of the height, 10% of the width of the screen). Is a one column Griview best? (I have had troubles in the past selecting the image height of a gridview programatically).
Any online tutorials precisely for this you have used?
If your view is going to have only one element per row, then the best and correct way of implementation is to use a ListView. The GridView should or can be used when there are going to be multiple elements per row. I believe the purpose of ListView satisfies its role for your need.
For creating a GridView with uneven rows similar to how Pinterest looks. Includes own OnItemClickListener and OnItemLongClickListener, selector, and fixed position restore. Check out this link, there is a library named "StaggeredGridView" : https://github.com/maurycyw/StaggeredGridViewDemo
As there is no text and only one column of buttons, it seems like I overlooked the obvious answer of using a scrollview of buttons, which is what I will go with. Thanks for your assistance.

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