0

I am trying to display a simple table with a series of buttons, and labels to the right of them (black text).

At first, everything look correct in the SDK Graphical Layout. Now, (without making any changes) everything looks correct in the SDK except for the fact that the text is not black, as such:

Eclipse Graphical Layout View

When I run it in the emulator, everything seems kind-of centered, and the text is the correct color, but only the very left-side of the text is shown.

Running in the Emulator

What's going on here?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/map_description_background">
    <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tableLayout1" android:layout_gravity="fill_horizontal">
        <TableRow android:id="@+id/tableRow1" android:layout_height="wrap_content" android:layout_marginTop="75px" android:layout_width="wrap_content">
            <ToggleButton android:textOff="Nautical" android:textOn="Statued" android:id="@+id/unitsButton" android:layout_width="wrap_content" android:layout_height="wrap_content"></ToggleButton>
            <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:text="Units" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/textView1" android:textColor="@color/maincolors"></TextView>
        </TableRow>
        <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <ToggleButton android:textOff="GPS" android:textOn="Magnetic" android:id="@+id/toggleButton2" android:layout_width="wrap_content" android:layout_height="wrap_content"></ToggleButton>
            <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:text="Heading" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/textView3" android:textColor="@color/maincolors"></TextView>
        </TableRow>
        <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <Button android:text="Help" android:onClick="clickHelpButton" android:id="@+id/helpButton" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        </TableRow>
        <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content"></TableRow>
    </TableLayout>
    <Button android:text="Done" android:id="@+id/done" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="clickDoneButton"></Button>

</LinearLayout>
Brad
  • 11,262
  • 8
  • 55
  • 74

1 Answers1

1

Eclipse SDK view and the emulator doesn't always aggree with each other ;) but the emulator usually aggrees with devices :)

I'm not sure why your code acts up, ussually it is something to do with padding/margin but could also be the textapperancelarge thing (not used it myself). Also don't use margin="75px" really not recommended to use hard coded values like px, use sp instead. See What is the difference between "px", "dp", "dip" and "sp" on Android? for reference.

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • Thanks. I think I need to use "px". The reason for the margin is that I have a 9-patch PNG background image, which has a ~75 pixel header. Since the header portion isn't scaled, I (believe I) should best specify the border in px. – Brad Oct 25 '11 at 17:39
  • Yes. It was the 9-patch background image! Upon further inspection, it was placing everything (i.e. my layouts) into the middle/stretchable area of the 9-patch! Don't know what that was happening! You'd think the "background" should affect the overlying content like that! – Brad Oct 25 '11 at 18:28
  • I've had similar issues before, the parent might have match_parent as height and width but it still wraps around closely to its children. Its like match_parent tells it that it CAN stretch but it wont stretch more if the children don't need it. – Warpzit Oct 25 '11 at 18:37
  • I found the fix here: http://stackoverflow.com/questions/3904852/android-layout-broken-with-9-patch-background – Brad Oct 25 '11 at 18:41
  • 1
    Ye makes sence, again these kind of problems always = margin/padding =) glad I could help finding the problem. – Warpzit Oct 25 '11 at 18:43