Grid or relative layout - android

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.

Related

What layout do I use for creating a form in android?

I need to create a layout exactly like in the picture. What layout can I use? If I use LinearLayout, I can't add the icons in front of the text fields without using so many nested LinearLayouts. With RelativeLayout, I don't know how to make the Textfields start always on the same height. With the Grid layout, I don't know how to put two Textfields in one row, like for phone and area.

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.

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

Android: Dynamically vary number of buttons in a custom View

I am learning Android by implementing a clone of Mastermind. I want to break up the screen (or View) into three parts: the board with the users guesses so far and feedback, a series of control buttons, and a series of buttons to pick the color of the next peg.
My instinct is to do this is a modular way. The layout files uses nested LinearLayouts (I know not the most efficient thing to do, but this is an educational experience.)
The "board" is a custom View where I do a lot of drawing with a Canvas. The buttons on the bottom are declared in the layout file. Notice the orange strip to the right?
Right now that is another custom View. I want to add a variable number of buttons to that custom View based on the number of colors the player can choose from. A button press would select the color for the next peg in the player's guess. (There are 3 versions of the game, easy, medium, and hard each with a different number of colors.)
So, how do I add a variable number of buttons to the custom View I am creating? Or am I approaching this in the wrong way? Should I use a prebuilt layout? If so, which one and how could I dynamically change the number of buttons in the layout?
Thanks for any help. Cheers!
You can do this in two ways:
Using a predefined layout and setting initially the property
"visibility" of all the buttons to "gone", then programatically you
can set the "visibility" of the buttons you need to "visible". The
"gone" property makes the button invisible and also not consumes
space in the layout.
Adding dinamically buttons to the main layout, first you will have to
create or "inflate" them.
The second options is more powerful, but also more difficult if you are learning.

Suitable layout for grid of buttons in android

I am confused with the appropriate layout design to be used for grid of buttons. I want to display a "textview and EditText" at the top. Below that there should be a 3*4 grid/matrix of 12 buttons(like cell phone keys), following another three linear buttons at the bottom of the root layout. (upper layout should not overlap the bottom buttons).
It would be of great help if anybody guide me in this regard.
UI layouts are done using xml files. Read about it before you start
While this is not exactly what you want here is a something to get you going.

Categories

Resources