Problems with android GridView - android

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!

Related

how to create a crossword puzzle shape in android

I want to create a crossword puzzle using android studio. the problem that I run into is I can't figure out a good way to draw the crossword puzzle the crossword
upon selecting a word from that shape. the user will access an interface that is designed specifically for that word. where to enter the answer
The problem I have is how to actually create that crossword shape, especially since I need it to be created dynamically afterwards based on the supplied data.
After 15 days of research all I can find are those possibilities:
Using Table layout with each cell representing a character. But this approach is not appropriate and not optimate and create many problems.
Using GridView with the unused cells set to be invisible. this is better but I think there is a better way than creating Grids only to set most of it to invisible.*
**I am sure there is a better way, but can't figure it out.
I know I have to give a code sample for what I have but I can't even do that till I know what approach I need to create this. If there is any suggestion to make my question clear that will be welcomed as well.
Neither. This calls for custom view for the word grid. While you can probably get it to work without one, it's going to look very amateurish, and you're going to be very hacky. Instead, you'll want a totally custom view doing its own keyboard input handling. Unless this is like a school project where looks and UX don't matter and you just need it done.

How can I make Xamarin.Forms Scroll view NOT push content off screen?

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.

An elegant way to keep integrity of RelativeLayout when animating 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.

add exact amount of elements in a ViewGroup

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.

DISABLE the auto arrange of widgets in eclipse

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.

Categories

Resources