Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Issue with TextView spacing in TableLayout in Android Studio

I'm currently finishing up an Android app, but I'm having problems with the layout when I run it in Android Studio's emulator.

I'm using a TableLayout to display rows of calculations. Each row has two TextViews, one is a static title and the other change based on user input.

The code for each row looks like this:

                 <TableRow
                    android:padding="5dp"
                    android:gravity="center_horizontal"
                    android:layout_width="match_parent">

                    <TextView
                        android:layout_height="wrap_content"
                        android:id="@+id/akv1BedSLabel"
                        android:text="@string/onebedSTitle"
                        android:maxWidth="100dp"
                        android:textSize="12sp"
                        android:layout_marginLeft="8dp"
                        android:layout_column="0"/>

                    <TextView
                        android:layout_height="wrap_content"
                        android:id="@+id/akv1BedSTotal"
                        android:text="@string/startingValue"
                        android:maxWidth="100dp"
                        android:textSize="12sp"
                        android:layout_gravity="right"
                        android:layout_column="1" />
                </TableRow>

However, for some reason, the TextViews are too far to the edge and chunks are cut off from the text even though there's plenty of space displayed between them.

I've tried assigning the TextViews to layout columns and setting maximum widths, but the text keeps wandering off the sides.

What could be causing this?

1 Answer

I've tried three different device layouts (Nexus 4, Galaxy Nexus and Nexus One) through AVD and had the same layout problem on all three. I haven't tried it on an actual phone yet.