which layout is best for moving buttons within - android

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.

Related

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.

2 LinearLayouts in the same position

So what I am trying to do is to have 2 invisible LinearLayouts with buttons they will be from the start to the screen.
On the onClick event one of them will appear with a translate animation,when the other is invisible and then on the other onClick event to close the open one and open the new one.
It will look similar to a sliding menu with the animation.
I want to know how the xml will look like in order to do that.
If it's possible with other layout (RelativeLayout), I also want to know.
Any tips on that?
There are multiple ways to achieve it.
Relative Layout definitely being the one as you your self know. :)
Add both the LinearLayouts with layout_width="match_parent" and layout_height="match_parent" and then toggle between them using setVisibility(View.GONE) and setVisibility(View.VISIBLE). Since View.GONE will remove one Linear Layout the other one will occupy the entire screen in its absence and vice versa.
You can also use FrameLayout. This by default places its children on top of each other.
Suit yourself. :)

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.

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.

Android Layout - UI Objects with the same position

How can I have two images stay on top of each other.
In other words, the position of image 1 is exactly the same as the position of the second image; one image is covering the other completely?
Use a FrameLayout and then put your two ImageViews inside it. Children of a FrameLayout stack on top of each vertically.
I think RelativeLayout is what you are looking for.
You should take a look at FrameLayout. Adroid have an example of using FrameLayout. Read up on this good example, and you'll have a better idea of how to tackle your problem.

Categories

Resources