Android TableLayout or GridView? - android

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.

Related

What is the right way to create layout for different screen sizes?

First situation
Let's say I have a screen with several buttons placed in vertical order.
I distributed available space between them using weights.
So, on a large screen buttons get bigger. That's what I want.
But how I make the text look bigger to?
Okay, I took a class from here Auto-fit TextView for Android.
But is that normal that android does not have a standard approach for this and we have to use a custom class?
That's weird. How do developers deal with it?
Second situation
Let's say it's okay to use this custom class.
I have a ListView
I want the items to increase their height as the height of screen increases.
How do I do that? I found a difficult way to do that, but it all seems like lots of troubles.
How do developers usually do such things?
Or maybe developers don't resize list items at all?
Maybe it's okay if they are set in dp and look quite small on big tabs?
I'm adding this as answer because I did a lot of typing.
If you're using Eclipse, you'll see that there are a number of folders in Drawables. They are essentially for sm, md, lg, xglg, etc... All screens fit into one of those categories. What people normally do is design a layout for each. And, yes, there are hundreds of individual sizes. And yes, it's a pain to create for all of them. But many developers do exactly that. And don't forget about landscape and portrait. Need layouts for those too.

GridView cells with different heights

I am creating an android app and I have a page that displays many cards at once. These cards have constant widths (so that two fit next to each other on the page) however they all have different heights. I want to display them in a grid formation where they fit together without any gaps like the notes app on the material design "Cards" page - http://www.google.co.uk/design/spec/components/cards.html#cards-usage -
(about 1/8th down the page). My question is, does anybody know how to do this? Any help would be appreciated.
Since we had RecyclerView, it's enough to setLayoutManager using StaggeredGridLayoutManager.
You can find more instructions here.
I have not implemented Gridview but I believe you want to manipulate its layouts, like in ListView. For a start, a link is at GridView. Look at setLayoutParams method. It will give you good ideas.

Android is it better to use a TableLayout or GridView

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.

Need to create spreadsheet like control, what should I extend ListView or GridView?

I am an experienced developer, but I'm inexperienced on the Android platform. So I am seeking some advice from developers with more experience with Android.
I am building a Honeycomb application using Fragments. One of the fragments calls for a vertically scroll-able read-only "HTML table-like" view with dynamically loaded data. Similar to a spreadsheet, I should have clickable headers which I can implement server-side requests to filter/sort the data.
I am pretty sure this Control doesn't exist yet, am I right? Do I have to build it?
Assuming I have to build it, which existing widget should I extend? ListView, Table, GridView?
I assume I would have one widget for the header, and then wrap the body of the table in a scrollable layout to handle scrolling while keeping the header visible. I am concerned that I might not be able to guarantee that the headers line up with the columns.
Thanks in advance,
Tim
Android layouts are pretty basic - there are not any shipped layouts that will really do what you are looking for automatically, but you could probably do what you want with a heavily controlled gridView. Android is also pretty bad about controlling multiple elements to fit within the screen size, as it's goal is to support multiple screen sizes and densities.
From what I understand your desire to be, I think the best solution is to create a nx2 grid view dynamically, and control the width of the view based on the device size. You would have n number of headers on the top, and you could fill the lower half of the grid with your textViews, or whatever data you wanted. The hard part would be keeping the widths of the grid elements under control and on the screen. In addition, you will probably find that you can only fit a small number of header items on the screen because of the phone's small size, so you may discover a better layout to fit your needs.

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