Random children placement in gridlayout - android

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

Related

Dynamic linear layout logic for given below image

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.

which layout is best for moving buttons within

OK first I'm not actually moving buttons I'm moving imageviews that have an onclick listener. What I want to do is drag multiple imageviews around inside a layout. I was going to use a FrameLayout but it seems that wont work for multiple items.
Can anyone tell me which layout is suitable for this?
thanks in advance
Linearlayout with a vertical orientation should do it for you..use margain_direction for fine tuning it further
Maybe a GridLayout would suit your needs? You can have one or multiple child views in each grid cell.

Listview with column flow

I want to add views to Horizontal listview (custom). The way i want to add them is:
Add a view (all views will be of width screenWidth/2) at top left of
the screen.
Add next view below that view.
Keep adding till the bottom of the screen is reached. When there is
no space for another view to sit, start adding to a new "column".
I have achieved this with a simple LinearLayout, now i am not getting any ideas how to do it with a ListView. The reason behind choosing a list view is that my app might contain thousands of such child views, and list view helps in keeping only those views i nmemory that are currerly needed.
Any help is appreciated guys.
You'll need to place GridView in HorisontalScrollView and sweat a bit to make it work. See here

Scroll another HorizontalScrollView though one is scrolling in android

I have two HorizontalScrollViews. If the user scrolls one ScrollView, the other ScrollView should also get scrolled. I am new to android and I wonder to know how can I achieve this?
If you want your two different scrollviews to scroll at the same time it means you only need one scroll view in which you cand put the content within the ones you have now. Try do make thinghs as simple as you can
Extend HorizontalScrollview like this: https://stackoverflow.com/a/6462630/1124160
onScroll in first ScrollView: http://developer.android.com/reference/android/widget/HorizontalScrollView.html#scrollTo(int, int)
Scroll the second one.
If your have number of items save in both HorizontalScrollView , then create a GridView and give number of columns equals to element in one HorizontalScrollView. In this way you can achieve your goal.

Android Advice - Images

Im new to Android and over the past few days I have been over many tutorials, I was wondering if you could help me with some advice.
I want images on top of each (not completely, there may be some overlapping) other with each image to be clickable.
Whats the best way to do this? Have each image in an image view? Can these be positioned on top of each other? And have onclick listeners?
Thanks for your help
Imageviews can be stacked by using the framelayout. The framelayout add each child view on top of each other based on the order of the childs ie the last child will be the top most.
Jep, ImageViews are appropriate. Add them to a RelativeLayout and add a onClickListener and you are done.
Have a close look at RelativeLayout's align* attributes.
HTH.

Categories

Resources