Sunday, May 22, 2011

Formatting - some tricky stuff

Today, I'm going to tackle an issue I've long been putting off. I need to get some aesthetically pleasing lines around the potential choices in my possible answers. I had taken out the separator lines based on a suggestion, but It's too confusing. Or, I could re-implement the radion button - but you can press on the whole bar.

http://stackoverflow.com/questions/2372415/how-to-change-color-of-android-listview-seperator-line.

For now, I'll change it to his:

android:cacheColorHint="#FF000000" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:textColor="@color/text_color"
android:divider="#FF000000" android:dividerHeight="4sp"
android:focusable="false">

Ok, I got the lines, but they're black. Worse, the top and bottom aren't covered.

I'm having some trouble figuring how to set the border, as opposed to divider line. A border will get the top and bottom of the list. Is it the view, or the ListView? Let's look at some apis from Eclipse...

Well, the view doesn't seem to offer much hope. How about ListView?

As usual SO to the rescue:

http://stackoverflow.com/questions/2658772/android-vertical-line-xml

Something like:

android:background="#333000" />

Ok, next up, is how to get a scroll vie around the text display; sometimes the text is too long and pushes the button off the bottom of the display.

We'll try the selected answer from http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android:

"You don't need to use a ScrollView actually. Just set the android:maxLines and android:scrollbars = "vertical" properties of textview in layout xml file. Then use the TexView.setMovementMethod(new ScrollingMovementMethod()) in the Code. Bingo!!!! It scrolls automatically w/o any issues.

But surely maxLines requires you to enter an arbitrary number; this isn't something that will work for every screen size and font size? I find it simpler to just wrap it with a ScrollView, meaning I don't have to add any further XML attributes or code (like setting the movement method). – Christopher Dec 19 '10 at 22:57"

Let's see what happens if we just use scroll view.



android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="0dp" android:layout_gravity="center_vertical|center_horizontal"
android:textSize="30sp" android:textColor="@color/text_color" />


No, I think I need to set maxlines.

Ok, I ended up with this:

android:background="#333000" />
android:layout_height="100sp" android:maxLines="3"
android:scrollbars="vertical">
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="10dp" android:layout_gravity="center_vertical|center_horizontal"
android:textSize="30sp" android:textColor="@color/text_color" />

No comments:

Post a Comment