Running Tipster on a real Android phone
I finally got a chance to run Tipster on a real Android powered T-Mobile G phone. I realised that you have to slide open the keyboard to enter values. When you do that, the screen orientation changes from vertical/portrait mode to horizontal/landscape mode.
And when this happens, the bottom part of Tipster which shows the calculated values goes out of the visible area of the screen. This is obviously not desirable. I had completely forgotten about this aspect of the 'screen orientation' when learning to develop applications for Android OS.
Viewing entire app in horizontal/landscape mode
But there is a simple solution. By using the ScrollView
layout container, the application gets an automatic vertical scrollbar when the phone is in 'horizontal/ladnscape' mode.
This allows you to scroll the application up and down and view
all portions of it. Remember that a ScrollView is like the
outermost cover for your application layout which contains your
'entire' application as a single unit.
This means that you need to have just one 'widget' or 'layout container' inside this ScrollView. In our case, there is just one TableLayout inside the ScrollView. The TableLayout has many sub widgets inside it, but that is okay. As required by the ScrollView, we are presenting just a single layout container.
Similarly you could have any layout like the LinearLayout instead of our TableLayout. As long as you wrap it all up in one big layout and then put this layout inside the ScrollView, you are all set to provide a scrollbar to the user when the physical area required by the application exceeds the the viewable area on the phone screen.
Never use a ListView for automatic scrollbars
You should never use a ScrollView with a
ListView,
since ListView takes care of its own scrolling. Most importantly, doing this defeats all of the
important optimizations in ListView for dealing with large lists, since it
effectively forces the ListView to display its entire list of items to
fill up the infinite container supplied by ScrollView.
Code snippet Enhancement-1 shows how the ScrollView is added as the parent layout for the entire application.
Enhancing the layout main.xml file
So all you need to do is add the lines 4 to 8 and 172 to your existing main.xml file. Now Tipster will allow you to scroll when the phone is in horizontal/landscape mode.
Comments and Feedback
Please visit my blog to post your comments.