Two column table on android - android

Hey everyone. I'm not big into UI programming so this may be an easy thing I overlooked. I am trying have a screen that shows 8 TextView in a 2 column x 4 row table. And, of course, I want the TextViews, that might have different lengths, to be centered. I tried this in a table layout, for obvious reasons but I feel like this is not the way to do it because it doesn't have much control where I put everything once it is in a row. Should I be using a different combinations of layouts or is there something I overlooked.
I can post my xml file if you really need but this is really more of a concept question than a specific one.
Thanks,
Jake

Can you explain why a table layout didn't work in more detail? If you're just trying to center the contents of the cells, you can set the android:gravity attribute in the table layout to "center"
EDIT: You can set the spacing between items using the android:padding attribute (Documentation). There are a number of other attributes in that link you can use to modify the way your table is laid out, as well as table-specific attributes at this link.

Check out apps-for-android's GridLayout. You may have to modify it a bit to get it to do exactly what you want, however, it's probably a good starting point.

Related

If you have an Android XML layout and you need to change only 3 things (2 textViews and 1 icon) what do you think is the best solution?

I have a xml layout for displaying some results, depending on the result type I need to adjust this view changing 2 textViews and one ImageView, the rest of the layout keeps without changes.
The solution I think is the best is to change the text and the image inside my java code (programmatically).
A friend suggests that is better to make a copy of the entire layout and change this 2 text labels and the image.
IMHO that leads into duplicated code that is why I do not think this is the best option. What do you think is the best approach ? Do you think of a better one?
Thanks in advance.
You are in the right direction. Using 2 different layouts for different results will be absolutely redundant. You can set TextView values by :
textView.setText("Your Text")
and Image resource programatically by:
imageView.setImageResource(R.drawable.yourImage); according to your result.

xml box layout or other suggestions

I am programming an android app for making work-fiches, main screen needs to show some summary of:working hours, parts used, remarks, ... , how can i design in xml these boxes the best way? I need a title, an summary content, clickable,...
The android design guidelines doesn't give me immediately a solution for it, also it is very difficult to find an example of it so i know which xml attributes to use, frame layout was helping me first but seems to give me some problems by now,
Thanks for your ideas in advance.
I suggest to go with Relative Layout, its the best layout present which requires a minimum no. of lines as compared to other layouts and align views with respect to each other. If you want views to be divided in proportion then it is recommended to use Linear Layout using weight concept.

Margins and paddings between elements in LibGDX

I have a VerticalGroup of Buttons on my screen. The problem is that buttons located very closely one to one. I want to add some spaces between buttons, something like padding or margin. I find pad method in Table in API, but VerticalGroup doesn't extends Table and therefore doesn't contain this method. Please point me how I can add some spacing between buttons inside VerticalGroup
Sample code
VerticalGroup buttons = new VerticalGroup();
buttons.addActor(btn1);
buttons.addActor(bnt2);
// ... and so on
Better late than never: libGDX uses TableLayout (https://github.com/EsotericSoftware/tablelayout) to order the widgets. When you follow the link and you go to the 'Padding' section, you will have an image illustrating your situation. In order to get the margin (the spacing outside of the button) you have to use the following code:
table.add(button).width(100).pad(10);
table.row();
table.add(lastButton);
This is very, very new, but for anyone reading this question in the future, there is a space method in VerticalGroup which is intended to allow you to define the spacing between elements:
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/VerticalGroup.html#space(float)
You can find an example of it in action, here:
https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/Scene2dTest.java
For those working with a slightly older version of libgdx, there is a setSpacing method that can be used instead.
Instead of adding padding from the parent (the VerticalGroup) add the padding to each element (the Buttons).
A libGDX Button is also a Table and Tables support various pad methods. Those are documented to change the padding around the outside of the table (or button in your case).

iOS: How to achieve relative layout

I'm trying to make an iOS version of my Android app. It contains text that looks like this:
There are three labels: title, author, and publication year. I need to display the full title, which may be several lines long. However long the title is, I want the author label to be directly below the title, and the pub. year directly below that.
In Android, I just used relative layouts to achieve this effect. How can I do this in iOS? Can Auto Layout do this for me somehow? If not, do you have any suggestions for effectively displaying this information in iOS? Preferably I'd like to achieve this using the storyboard.
In iOS you use InterfaceBuilder IB for layouts - it's drag and drop - not like Android layouts.
Search for IB tutorials - it is really straight forward and you see what you get:-)
I also searched quite some time a way to achieve android-like layouts in iOS (without the hassle of computing every positions for each subviews).
I eventually gave up and coded a fast equivalent of VerticalLayout and HorizontalLayout. Here's the repo (it's ARC compliant) :
https://github.com/kirualex/iOS-Layout-helper
It's sketchy but it does the work !
Put simply relative layout organises items on the screen relative to something else. Like linear layout, relative layout is commonly used by android developers. I myself do like this layout and have used in the development of my applications before. See
http://developer.android.com/reference/android/widget/RelativeLayout.html and http://developer.android.com/guide/topics/ui/layout/relative.html for more information on relative layouts.

How to create "floating TextViews" in Android?

I'm programmatically putting various TextViews into a LinearLayout with a horizontal orientation.
After 2h of research I couldn't find out how to tell Android not to squeeze all the TextViews in one line but instead to "float" non-fitting TextViews into the next line.
I know there isn't something like actual "lines" in a LinearLayout, but how can I tell the TextViews to actually behave like floating DIVs from the HTML world?
Thanks alot!
Use RelativeLayout. In addition to allowing to you to set up Views relative to each other, it can also align them relative the parent.
Specifically, look at RelativeLayout.LayoutParams, with which you can do something similar to float with alignParentRight/alignParentLeft and so on.
It sounds like you're looking for something like a FlowLayout in Java? I found an answer in this question that looks immensely helpful for what you're trying to do.

Categories

Resources