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 trialArnas Misevicius
98 PointsMy text doesn't fit in the textbox
My text just cuts out after it reaches the end.
5 Answers
essam rashad
245 PointsI had the exact same problem as Arnas Misevicius above. When following the video using the latest Android Studio, the xml shows this by default:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Did you know?" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Ants stretch when they wake up in the morning."
android:ems="10"
android:id="@+id/editText"
android:textSize="24sp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
I realized the bottom half of the above code looks different to Ben's, so I copy pasted Ben's code into mine and it worked fine, i.e. the text is now two lines and fits within the box. But the question still remains, what is the difference between my code and Ben's? i.e. what explains the different "output" if that makes sense (sorry, I'm noob lol).
Ben Deitch
Treehouse TeacherHey Arnas! Your TextBox is likely too small for your text; try making the TextBox larger. Or if the issue is that you think the text should be wrapping to the next line, try setting the 'singleLine' property to false: android:singleLine="false"
Nick Post
Courses Plus Student 3,155 PointsFalse is actually the default for android:singleLine... In the most updated Android Studio, that attribute is deprecated and it's suggested to use maxLines. The problem is, even when maxLines is set to 2, the text is too big for the screen when following the video. When we input "Ants stretch when they wake up in the morning.", the preview shows the text cut off; for example, mine shows "Ants stretch when they wa"... so it's like the text will not word wrap automatically as shown in the video. Note also this is at the 24sp. We can make it smaller to fit, but I think the question is how to see the words wrap as shown in the video.
Any further suggestions to fix it?
Ben Deitch
Treehouse TeacherHmmm... would you mind sharing the code in your activity_main.xml? I haven't been able to replicate this.
Nick Post
Courses Plus Student 3,155 PointsSure! Here's what I have:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_fun_facts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="p05tmanlabs.funfacts.FunFactsActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Did you know?" />
</RelativeLayout>
Also, I have tried changing the layout_width/height (in both RelativeLayout and TextView) to wrap_content and match_parent with no luck Is there any way to post a screenshot of what I see? I'm not finding an option to do so
Ben Deitch
Treehouse TeacherThere should be two TextViews in that RelativeLayout. Here's what I've got if it helps:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Did you know?"
android:textSize="24sp"/>
<TextView
android:text="Ants stretch when they wake up in the morning."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:id="@+id/textView"
android:textSize="24sp"/>
Remko de Ronde
4,779 PointsIt was the following line for me that I had to delete from the code, which solved the problem:
android:inputType="textPersonName"
I guess this inputType blocks some options on changing parameters of the text or it comes with some standardized parameters. I am not 100% sure what the inputType line does actually.
Jeremy Sandstrom
267 PointsThis worked for me:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:id="@+id/editText3"
android:text="Ants stretch when the wake up in the morning"
android:textSize="24sp" />
essam rashad
245 Pointsessam rashad
245 PointsOkay guys, after looking into the problem a few minutes, i found out:
You have to go under the "widgets" folder as explained in the video....as opposed to the "TextField (EditText)" folder.....under the Widget folder we will find TextView (note, in the video [in the older Android studio], Ben dragged out "Plain TextView" from the Widgets folder......while in the new Android Studio, it is just called "TextView")...The confusing part is, is that there is another thing called "PlainText" which comes under the "Text Fields/EditText" folder. So I must have dragged that one out onto the screen initially.
Ben, could you explain the difference between "TextField (EditText)-->Plain Text" and "Widgets--> TextView"?
Thanks!
Nick Post
Courses Plus Student 3,155 PointsNick Post
Courses Plus Student 3,155 PointsYeah exact same problem here! Great work finding that "extra" Plain TextView in the Widgets folder! Copying/pasting Ben's example worked for me as well, though beforehand my code example looked just like the example you provided.
Ben Deitch
Treehouse TeacherBen Deitch
Treehouse TeacherSo it looks like Android Studio may have changed how some of the buttons work (I hate when they do that :P). Either way what matters isn't what those buttons do, but rather the XML they create.
There's two different UI elements (Views) that we've seen here: TextView and EditText. A TextView is just that, a simple View that contains text. And an EditText is a specialized type of TextView that allows the user to interact with it. The problem is that your EditText has 'ems' set to 10, which means the width of the EditText will be about 10 M's (E.g. MMMMMMMMMM).