This is I think the first time in my whole programmer's life that I ask something. Before I was always able to find the solution by myself or on internet. But here, I give up ...
About the tittle, of course ViewGroup is abstract, but the idea is to have a element that can handle many other child elements in a "list".
Here is the problem. Imagine you have your ViewGroup (or other descendant class), and you want to add as much as possible elements in this space without having a scroll bar or some elements truncated. The elements will be one under the other.
For exemple if 4.65 elements can fit in this free space, then only 4 will be added. Because adding a 5th will result in a truncated element, because there is simply not enough space to add 5 elements.
I tried some things like calculating the space available in the (in this case) LinearLayour, and adding a "pilot" element to measure it, and then to know how many other I could add. But this is not working.
The height returned by the "pilot" element is incorrect.
I tried so many thing, that I can't explain everything here, but if you have some ideas on how to do it, just say.
It's been 3 days I'm on this problem, it makes me crazy.
Finally I found the solution. I can't really explain it here, because I use custom home made components, but I was able to fin the source of the problem.
While creating the simplified class to demonstrate the problem, I found that in fact everything was working correctly. So I compared the simplified class with my project's one, and modified them until they were almost the same.
I found the source of the problem, even if I don't understand why there is a problem. In fact, if you set the textsize via a constant before doing the calculation methods (pilot element, space calculation and so on), it works perfectly.
If you modify the size by calling an accessor(setSize) even prior to do the calculations to know how many elements you can add, it won't work the same.
That's really weird, because I modify the textSize before doing the calculations. It should work the same.
Anyway. I found a trick using Threads/Handlers that solves my problem. It was difficult to find the problem, but impossible to understand why it happens.
Related
I am posting and answering my own question because this issue took me days and days to figure out, and finally I did some half-baked kludge, and then months later I found the actual answer, and I want to spare others that.
Problem: to get iOS text entry elements to scroll up and stay visible when a keyboard appears, in Xamarin Forms the easiest way is to use a ScrollView, BUT for some reason any time you use a ScrollView the dang thing resizes its content so that some of it is slightly off screen.
Content not inside ScrollView:
Content inside ScrollView:
As you can see, for some darn reason the ScrollView has its own opinion about how to lay out its contents, and that opinion is that some of it should always be off-screen.
What the heck? I've tried changing layouts and using different kinds of nesting views and adjusting layout options and margins and everything I could think of. The dang layout just always changes without me telling it to!
How do I make it behave?
ScrollView has an Orientation setting to determine the directions it can scroll. You can set it to Neither right there in the XAML, and all your content will be back where it should be.
Note that if you actually want scrolling behavior, this will mess that up. But if you're only using a ScrollView to get its nice behavior around keyboards appearing and disappearing, as I usually am, that shouldn't matter.
When I rotate the screen on a tablet, my widget's list view disappears and the buttons become unclickable. I'm not sure what happening with the most recent remote view to cause this. Any suggestions?
Here is my onUpdate function
onUpdate
Since we do not have the full code, it's kind of hard to give an actual answer to your problem.
However, I might have an idea & the cause of your problem could be in your .XML file. The same way your app looks great in a certain rotation, most surely on the one you originally designed your work on, it is very possible that it might result in problems when you changed the rotation.
However, it all depends of the layouts you are using & how they are used. I would advise to share your entire code so we can go through it.
Ok, so...
I know, there's been a real amount of questions about it, but it either didn't work, or was really fixed in a hard way. Oh, and that's my second day trying to do it, so please, accept my apologies about that and help me for Chet Haase's sake.
I have a button on top of a fragment, and a RecyclerView below it. When i press the button i want it to disappear and a new RelativeLayout with textfields to slide from the top.
I don't want to make it with animateLayoutChanges="true", cause it's not exactly what i was meant to do, and i want rather learn, than do it.
I tried to do it with widget.animate().translation... and the result was that one widget was just thrown in it's place when the rest of layout stood still. That's not what i meant to do.
I tried also to make an "new TranslateAnimation" since it has this "setFillAfter/Before" attribute... but that did not help me neither.
What i tried as well was to update the layout somehow adding to id margins and stuff (don't remember anymore, and i'm in work right now trying to figure it out, sorry) as it was described in some questions.
But none of that worked. I don't include code right now, cause i already tried to do it in some dozens of different ways.
Could you please tell me how to move a widget and make the rest of them to move with it? Is it possible?
I've already got it going once using setVisibility,animateLayoutChanges and animation combination, but that was massive and dirty as a baby duck.
Edit: oh, i almost forgot about it. Another problem is that when i animate/move a widget, only the rendering spod changes, but the real spot of it stays the same (ex. a onclicklistener)
Ok, me again.
I did it this way, that - let's say - i want to slide a button up and remove it.
So i animate it and all the other widgets (right, i can make a ViewGroup) up, put a listener on animation, and on "onAnimationEnd" i clear all the animations and set the visibility to GONE.
The animateLayoutChanges must be set to false
Still it's not what i wanted, so i'd be indebted to anyone who shows me another, better way.
I'm fairly new to android programming (making the switch from Windows programming to Mobile Platforms.)
Problem: Every time I add, let's say, a text view, I get a green box around it that will put it in a location. When I add multiple text views, I go to place it down under another text view and everything in my app shifts, and moves everything into a stack on the upper left most part of the screen. It seems like every time I move one thing, 5 other things move with it.
Question: Is there a way to disable that function?
Go to your layout, right click it, then click on change layout. I changed it to absolute layout so I can move any or my widgets around the screen as much as I wanted without the movement effecting other widgets. Hope this helps
Android forces you to develop without a pixel-rigid notation. Basicly you have a set of Layout types (Linear, Relative, etc) that stablish a relation between the child's elements.
Therefore, it is important to know those Layouts, how can you connect them and how their childs are arranged.
In eclipse you can add elements but some things eclipse doesn't know how they are related. Eclipse will update the new data, and therefore moving all kind of views out of the way to update into the new hierarquy you defined. Therefore you can't remove "auto-layout". Even if you change to Absolute Layout (like David suggested) you are not removing the "auto-layout" feature. You are simply telling eclipse that you want to arrange your things with absolute positioning. However, absolute positioning is not advisable since you have several devices with different resolutions.
I advice you to read some information about Layouts and then try to use the XML. Don't be afraid. It can become quite easly. Actually, I prefer XML to interface builder in eclipse. After you get some idea how layouts work you can use make a better use of the interface builder.
I am trying to display 2 columns of text in a GridView in android. I create a TextView for each cell of the grid. Everything seems to work well until the TextView tries to wrap the text to a second (or more) line. When this happens, sometimes the second line of text overwrites the next cell, rather than causing the cell to expand to fit the text. All I have to do to get the text to display properly is click one of the cells in the grid. This seems to cause the grid to repaint and then everything gets displayed properly. I have tried any number of things to fix this problem but nothing seems to help.
Is there some property that I have to set on the TextView or the GridView to allow the cells to expand to fit the text? Or is this just a glitch in GridView that I have to live with?
BTW, setting android:singleLine="true" prevents the word wrap and solves the problem but it isn't an ideal solution because I really don't want the text to be truncated.
At a quick glance, I'm afraid you might have to do a work-around. I know it seems like a glitch, but it may be more ideal to continue to have your views start a consistent location instead of constantly having them shift based on content. I know this is a pain for what you're trying to do, but keep in mind that this was designed for hopefully the best solution for any application. Anyway..
One workaround I would propose might be manually updating the beginning of the views that get written over. I know it's not exactly ideal, but you can figure out where to place it based on the properties of your view. This doesn't feel like a particularly elegant solution though, so I'll try to cook something better up and/or post sample code. Good Luck!