Android is it better to use a TableLayout or GridView - android

I am developing an app and I would like to have 12 ImageButtons (3 x 4). centered in the android screen and the center section of the screen where the ImageButtons are located to have a color or gradient background.
Is it best to do this with a TableLayout or a GridView... or maybe something else. I am a newbie to Mono and Android so any help is appreciated. I was hoping to do most of the layout in the designer, but I am not sure of the best approach.
Can anyone point me in the right direction?

I think GridView is better to use as it supports recycling of views. In case of TableLayout all the views remain in memory.
Even if the no of buttons increases, GridView will take care of it.
Make sure you are implementing view recycling correctly, or otherwise you may have a memory leak.

If there are only 12 buttons, a TableLayout would probably be simpler to implement because you don't have to mess with the adapter. If you need scrolling or the number of buttons may increase over time, you would probably be better off going with the GridView.
You may want to look into the GridLayout in the Android Support library v7. It is kind of like the TableLayout but seems simpler to do things like just wrap button into a set number of columns.

Related

Is it good practice to only use LinearLayout for a Layout that only plans on using one screen?

I have a screen in my Android Application that only takes up one screen. Because of this, I thought it would be really quick and easy to just use LinearLayout as my base layout:
I thought this would be good. However, I am thinking, what if someone uses a 2.7 inch screen on their smartphone? Or they do split view. They might not be able to see everything without scrolling. So, is it good practice to do the layout the way I am doing it or is it always good to allow the user to scroll to see everything?
Since many different devices exist, some with very tiny or otherwise abnormal screens, it is a good idea to make the layout scrollable when needed.
This is achieved by encapsulating your layout in a ScrollView.
Other popular methods to tackle this are using ConstraintLayouts, or the legacy Relativelayouts, which are placed relatively to each other, and relative to screen borders.
What if a layout gets partially off-screen? Maybe it is no big deal, but maybe it hides an essential part of the layout (e.g. a 'next' button, or some important information). So yes, your worry is justified.
As I believe it is good practice to make an app work on as many different phones as possible, I do believe it is good practice to make sure a layout does not appear partially off-screen.

Android wallpaper program layouts

When I look at several of the more popular android walpaper programs, (HD Wallpapers and the like), they all seem to have a very similar layout with 4 pictures in a 2 x 2 grid where each takes up approximately 1/2 of the parent's respective width and height. After not having a lot of success emulating this with various combinations of layouts and objects, I am trolling for a pointer. Anyone who could get me pointed in the right direction would be greatly appreciated. Is there a standard mix to achieve this sort of view?
Side note: Please be gentle, it's my first time... asking a question. ;)
You could use a GridView with android:numColumns=2.
You can see a GridView example here. You would set the height by manipulating the LayoutParams on the views that you put inside the GridView (via its Adapter).
If that doesn't float your boat and you're not doing much scrolling, you can always create a TableLayout with TableRows of 2 Views apiece, or a vertical LinearLayout containing two horizontal LinearLayouts of 2 Views apiece.
What have you tried already? Can you expand on your use case a little bit more? Do the images need to scroll? Can they be static? Will there be more than 4 images on a page?

Gallery within a gallery?

I hope I'm not too vague with this question. For some reason I've developed an inordinate fear of being ambiguous with my SO questions :-)
I need to make a design decision and, having just recently started in my Android efforts, I thought I might ask about its potential dangers among those who've been in the trenches for awhile.
I'd like to build a gallery within a gallery. The outer widget views will scroll horizontally, while the inner views--being galleries themselves--will scroll vertically.
Has this been tried/crashed/burned in the past? If so I'll rethink my UI, but I wanted to ask in advance before I spend a lot of time chasing the wrong dog.
Thanks,
Jeff
The gallery widget cannot scroll vertically. There's no way to change orientation, it can only be horizontal. You can build it custom, something like attaching image views to list views and such, or you can use something like a wheel scroller, like this one, called android wheel, and do some tweaking to make it look and work the way you want. These two SO posts might help as well, for the vertical aspect.
Lazy load of images in ListView
Vertical gallery in android

Android TableLayout or GridView?

I want to create a grid of words approximately three wide and eight deep. I would like to be able to select some of the words and do a fade animation on them. I would also like to know when a word has been selected. I have been looking at TableLayout and GridView to do this. Would one of these be better than the other to do this? Is one of them more adaptable to the different screen sizes in Android than the other?
I've played around a bit with tablelayout (and tablerow) and it will definitely do the trick, I guess more importantly the question is whether you expect to have a fixed number of columns or not ("approximately" doesn't help...). If so and you have very good control of what goes in the table/grid, tablelayout may very well be what you're looking for (I just find it simpler, but maybe I'm wrong).
They both can adapt to screen size with the right layout instructions, and proper programming will give you similar results.
But then, if you allow the screen to rotate, you may want to use gridview
parameters, parameters, parameters...
I think a TableLayout would be more easy to use. For a GridLayout you need to build custom adapters and so one which result in a more complicated application.
Looking at different sceensizes, a GridLayout will choose a good number of columns and rows by itself according to the content and it will be more flexible with adding items.
Also the GridLayout will be more flexible but it is some more work to make.

Android Layout On Top of an Image

I am struggling with a Layout Problem on Android. This is very simple to do on the iPhone, but with the various screen sizes and the Layout classes available. I am having a hard time doing this.
One thing that I have noticed is that setting backgrounds on objects in the xml really messes up the layout on the device. I generally have to put in a FrameLayout and an ImageView to get a background.
So Am trying to get to this. http://www.calidadsystems.com/images/AndroidListItem.png (Sorry I don't have enough pts to post the image)
his is a status view and is an item in a List View. There are 8 TextViews that need to be set. Each of the 222 fields will change. The current background has the colors in there at specific locations and I am trying to line up the Labels and TextViews to get the picture below. I built this one with AbsoluteLayout which is deprecated, but it also does not work very well on the device.
I have constantly struggled with the layouts on Android. Does someone have some good sample code that could do this?
You're probably going to want to use a RelativeLayout. You can use the android:layout_alignTop="id" attribute to make the rows be in line correctly. And android:layout_alignLeft="id" for the columns. Other than that its just a matter of playing with the android:layout_marginLeft="XXdip" attribute to get the space between them how you want it. Check out this page for an overview and examples of all of the Layout types. Here is some more sample RelativeLayout code. And one more page with another example. RelativeLayout is a bit tricky to get used to but once you've used it a few times its pretty easy to understand and get the Layout that you want. The benefit of it is that your UIs look nice on several different screen sizes when you define them this way.
Why not just composed the layout in a table layout and set the table layout's background to a custom made graphic you make? This should work well with you. Specifically the design of your design would be like 4 columns with x rows. Then using the strechcolumn property, you should be able to accomplish what you are trying to do!
If you scale the graphic properly, then you shouldn't have this problem overall.

Categories

Resources