PDA

View Full Version : Alignment problem


counterpoke
08-16-2004, 11:27 PM
All I want to do is align the text "center", but it just won't work :(
It will either changing it right, center or left does nothing. If I add a "<view>" and make it the parent of "<text>" what happens is weird. left will leave it normal, and right moves it to left exactly so that it makes it look like it is aligned to the right on the wrong picture. If you say center, it looks nothing like center. Could you help?

This is the code that matters:
<!--This class provides picture buttons with width=height=60-->
<class name="picButton" extends="basebutton" width="60" height="60" />
<!--This class provides picButtons with a caption at the bottom (60,80) (x,y)-->
<class name="viewbutton" extends="view" width="60" height="80"
resource="Home">
<attribute name="text" type="html"/>
<simplelayout spacing="2" axis="y" />
<picButton name="pic" resource="${parent.resource}" />
<text width="60" fgcolor="0xC8E5CA" align="right" name="subtitle"
text="${parent.text}"/>
</class>

And this is the specific line of code I'm having trouble with:
<text width="60" fgcolor="0xC8E5CA" align="right" name="subtitle"
text="${parent.text}"/>

antun
08-17-2004, 09:20 AM
The best way to debug this kind of scenario is to give background colors to the elements you're having problems with, so you can see exactly what is going on:


<text width="60" fgcolor="0xC8E5CA"
bgcolor="yellow" align="right"
name="subtitle" text="${parent.text}"/>

If you give its parent a different bgcolor you'll see why nothign is happening.

-Antun

counterpoke
08-18-2004, 08:07 PM
So i did this:

<class name="viewbutton" extends="view" width="60" height="80"
resource="Home" bgcolor="0xffffff">
<attribute name="text" type="html"/>
<simplelayout spacing="2" axis="y" />
<picButton name="pic" resource="${parent.resource}" />
<text width="60" fgcolor="0xC8E5CA" align="center" name="subtitle"
text="${parent.text}"/>
</class>

and basically added "bgcolor="0xffffff"> to the end of the class name. It showed the attached pic.. it highlights the area i expected it to....

-Dexter

antun
08-20-2004, 10:15 AM
Your case boils down to this:


<view width="60">
<text width="60" align="center" />
</view>


If you put a 60px wide text field in a 60px wide view, the text field will take up the entire width of the view and center alignment is going to have no effect on the appearance. Remember it's the text field that aligns, not the text in it.

If you want it to appear like it's centered, then the text field has to be exactly the same size as the text inside of it:

<text resize="true" align="center" />

Note no width specified.

-Antun

counterpoke
08-20-2004, 01:15 PM
Thanks a lot Antun.

hunterino
04-19-2005, 08:19 PM
I am trying a multiline center

<text multiline="true" align="center" resize="true" text="Hello asdfasdfasdf asdfasdfasdf asdfasdf of you and lets see if it will wrap or if it's just a wish"/>

It puts in no breaks, but as long as the line is smaller than the width it works.

Thanks
Michael