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.
Related
For e.g. I want to show tags to some article (just like we have tags attached with each question on StackOverflow), I would like to show them like this:
Where the tags can be of variable length and they should span across multiple lines if they can't fit in the given width. I tried out LinearLayout and RelativeLayout but they don't seem to be able handle such 'auto' arrangement scenario. What layout or methodology should I use to achieve this effect?
This requirement is known as FlowLayout and I found couple of solutions as open source libraries to achieve this effect:
ApmeM/android-flowlayout
blazsolar/FlowLayout
I've added two controls, say Text Box.
But it is added side by side.
I want to move the objects, like in Visual Studio.
Can anyone help me how to do it?
you can use Relative layout for placing your views, so that you can place them variably like left of,right of, above, below, align etc.
You want one above the other? Try RelativeLayout and you can specify layout_below.
This seems like a really basic task, but after a lot of searching and research, still haven't found a clear answer. I found GridView, but not sure this is how you're supposed to do it.
I've found several apps that have UI elements similar to what I need, for example the top buttons of the android market.
That can easily be accomplished with a horizontal LinearLayout that contains a set of Buttons or ImageButtons. The rest is just styling.
See Hello Linear Layout to get started.
I basically want to have several views aligned with each other using a relative layout. I can do so using xml, but unfortunately I can't find any documentation that tells me what methods I need to call to get the same effect in code (All the examples and things just use xml). Since the imageviews are being made dynamically xml isn't an option for what I want to do. I've looked at layoutparameters which seems to let me change some options, but I'm not seeing a method that will let me change alignment relative to another view. Any help is appreciated.
After playing around with it some more found that addRule is the method I need. Couldn't find it because I was looking for something with the term alignment in it.
Check out setLayoutParams in the Android documentation:
https://developer.android.com/reference/android/view/View.html#setLayoutParams(android.view.ViewGroup.LayoutParams)
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.