Friday, July 29, 2011

Aligning a textview within a scroll view

All right, I noticed a couple of things I need to clean up on this app. The first one has to do with centering aligning text from the top on the english display. For some reason, it seems to be aligning to the middle or bottom vertically, but only when there are two lines - in other words, when there's a scroll, but I think only with two lines.

You can see from the screen shot:





And that's Let's take a look the layout:


android:layout_width="fill_parent" android:layout_height="60sp"
android:layout_gravity="top|center" android:gravity="center"
android:scrollbars="vertical">
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="top|center" android:layout_gravity="top|center"
android:background="#FFEBD5A8" android:paddingLeft="10dp"
android:paddingRight="10dp" android:textSize="25sp" />


So, I have both the layout gravity at top center, and the gravity at top center. The only think I can think of to try is to make the gravity of the scroll view top|center, instead of center as it is now.

Let's give it a try:


android:layout_width="fill_parent" android:layout_height="60sp"
android:layout_gravity="top|center" android:gravity="top|center"
android:scrollbars="vertical">
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="top|center" android:layout_gravity="top|center"
android:background="#FFEBD5A8" android:paddingLeft="10dp"
android:paddingRight="10dp" android:textSize="25sp" />


Ok, problem with the licensing server...ok, I'm not connected on Panera. This game really should be allowed to be played offline, shouldn't it? Well, it is, it's only a unique case of going through a gateway. Of course, maybe I should force a check every once in a while. Sigh. There's so much you can do to lock down an app.

Rats. It's still the same.

The only thing I can try the padding:


android:layout_width="fill_parent" android:layout_height="60sp"
android:layout_gravity="top|center" android:gravity="top|center"
android:scrollbars="vertical">
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="top|center" android:layout_gravity="top|center"
android:background="#FFEBD5A8" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingTop="1dp" android:paddingBottom="5dp" android:textSize="25sp" />


Ah, ok, I think I get it. The top|center means it will actually push the top text down the amount of its default or explicit padding, I guess. I could center it vertically which would work in the case of one and two lines, but would at least partially obscure the top line in the case of text of three lines or more.

I think the only way around it is to increase the size of the text just a little bit. I'm think maybe the scroll view affects that. Maybe if I make it, like 65sp or something, and dump the padding top and bottom:

android:layout_width="fill_parent" android:layout_height="65sp"
android:layout_gravity="top|center" android:gravity="top|center"
android:scrollbars="vertical">
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="top|center" android:layout_gravity="top|center"
android:background="#FFEBD5A8" android:paddingLeft="10dp"
android:paddingRight="10dp" android:textSize="25sp" />



Ah, I get it. It's not scrolling any more, which means not matter how much bigger I set the scroll_view layout height, because the textview layout_height is wrapping the content, it's not going to get bigger. In other words, the wrapped textview is now smaller than the (increased) layout height. It doesn't look that much different, but now we're working with default Android values, so I'm willing to settle for it. That's a wrap for now. The new image is below. Can you see the difference? It's an improvement :)

No comments:

Post a Comment