Android - Rearranging elements according to number of child - android

I'm building an Video conference application, where I want to rearrange participants' screens to be dynamically rearranged when anyone joins or leaves. e.g. for one participant, his screen will be in center, for two they will be side by side and for three triangular and so on...
I'm using relative layout and adding views in the relative layout programmatically at joining.
what approach should I use for the auto layout alignment with proper aspect ratio. Please help.

Because you haven't provided code, I can give you the logic I would use. First, just check how many participants are there.
Next, create mapping with ints as the tag, and string as the value. Each tag cooresponds to one int, the input:
(blogs.endjin.com)
Now, have different layouts based on that string value. For example, for the string "side by side" which corresponds to the int 2, you can inflate a different layout, or dynamically change the current one, to have the people side by side. I suggest you use a switch to check this, and have the different cases based off of what the string of the mapping is:
(www.slideshare.net)
You want your statement list-x in the diagram, to be getting the value of the mapping with the tag of the integer amount of people there are.
Steps in a more clear, easy to understand way that I have listed out for you:
Have a mapping for each amount of people. Amount of people is the
tag, and the layout is the value.
Look for the tag based on amount of people, and check the string
output, which is the layout. See what the string output is by comparing it with something that can expand the layout
You need to compare the strings, or the output.
Inflate appropriate layout based on string.

Related

Dynamic Android Layout Scaling (How-To?)

I'm stuck and I think wisdom (aka experience) is the only solution.
I need to be able to have boxes on a screen with data inside each box. The number of boxes on the screen needs to be able to change and the boxes need to scale accordingly (as well as the text data inside of them) to allow for the additional boxes.
Example: I might start with only 8 boxes which are evenly spaced and displaying data at a reasonable font scale.
As I add more boxes I need the rest of the boxes to scale down and allow everything on one screen.
I am currently attempting to use a TableLayout, but I'm not certain how to make everything scale correctly. Also, I'm generating everything programmatically by extending the TableLayout. Can someone point me in the right direction. Is there a better layout method that I'm not seeing? I'm sure I'm not the first person to need this, so are there examples available that I'm just not finding by searching?
The eventual solution was to build my own scaling function which took screen pixel dimensions and calculated the appropriate margin offsets to use on a relative layout. It requires a complete redraw each time the scaling factor changes, which is annoyingly resource intensive.

dynamically configuring views for a ViewPager widget?

First let me say that I'm very new to android development (although I have a good understanding of the basics of java), and I am building a magazine reader app for a campus publication I work for.
I want to display each article using a ViewPager widget. I'm going to build a java program which enables the magazine editor to post articles in .txt format onto a server, along with images associated with each, and have the android app periodically download these articles to a local folder.
I'm a little confused about how to construct the views for each ViewPager from the text files. Somehow my logic needs to determine the size of the screen running the app, in order to know how many words can fit on each screen.
Is this right, or am I fundamentally misunderstanding ViewPager somehow? If so, how might I structure the program to configure the views dynamically based on the txt + images given to it?
From what I understand, each page will contain as much of the article as possible, and when the user selects the article they will be able to see the entire thing. Something like this, but so it fills up the entire screen?
If this is the case, you have two options here:
Just ellipsize the textview so that it ends with a "..." at the end. Probably the preferred solution.
Resize the TextView to fit all your text (Auto Scale TextView Text to Fit within Bounds).
EDIT:
Here's a different interpretation of your question.
From what I understand, you're trying to have something like an eBook reader with an undefined number of pages; kind of what Flipboard does:
Basically, once all the text fills in the entire area you want to have it continue to the next page.
The easiest way to do this, if you do not need native performance, would be to just use a WebView, split the text across several columns, and have only one column be visible at a time.
However, it is certainly possible to calculate how tall the entire text would be and then split it up accordingly; i.e. Pagination in Android TextView
It seems similar questions have been asked and addressed: Splitting a TextView into multiple TextViews relative to screen height (see the accepted answer).

Dynamically Sizing the height of ListView components

for practice I am writing an activity that takes a string from a local DB and puts it into a listView. However the string's are of different length, ranging from a couple of characters, to a couple of sentences. Write now I can take them and place them in a listView but, not all of the strings fit. I was curious if/how you can dynamically choose the height of each part of the list view so that the entire string can fit in it.
Just make sure your list item layout is using wrap_content for its layout_height attribute. If you're using a fixed height, it won't scale to fit larger strings. If you want the lists a specific size except for in situations as mentioned, you can also add a android:minHeight attribute as well with the dimension you want as standard.
Also, make sure your TextView is set to multiline (attribute android:singleLine="false").

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.

Two-pass UI Layout : Why?

I've noticed that Android, WPF, and Silverlight all follow a two-pass layout pattern. There's a recursive Measure() method that gets called to size the element, possibly multiple times. Then a recursive Layout/Arrange() method is called which lays out the exact positions of children in their parent control, and will also set the final size of the control.
My question: why is this split into two passes, especially when, for some types of controls, Measure() can't compute the actual size of a control without actually laying out the positions of the children? Is there some type of layout minority case that is made possible by this?
I'm trying to create my own UI toolkit, and I'm currently leaning toward a one-pass Layout() pattern, but I'd like to be convinced whether this is wise or not.
Thanks for reading this :)
Sean
The reason for the two passes is that any element in the structure can influence the remaining available space of the others.
Some element wish to take the largest possible space while others have fixed dimensions. You can also have elements with only a max width set. It creates an equation that can not be solved in one pass.
The different panels in the hierarchy ask the elements what size they need in the first pass, then distribute the space among them according to each panel's nature, and finally informs each element of its allocated space.
EDIT: Some more explanations
The main drawback of a single pass layout is that you are handling each element sequentially. A first element takes a certain amount of space and the others take the rest. Why is this element the first? Try your algorithm with different element order, and you will have different resulting layouts.
A two pass layout simulates a parallel behavior where each element influences the whole layout.

Categories

Resources