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 Build a Simple Android App (retired 2014) Pretty Little Things Positioning Text Using a Linear Layout

Positioning items in a relative layout

I tried the method describe in the video, I mean, putting items in a LinearLayout, but when I change the screen type, the LinearLayout and the items are still not arranged anymore. How to fix this? Thanks !

4 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Layouts are tricky. I want to cover them in a lot more detail in an upcoming project.

How do you change the screen type? A different size screen, or a switch to landscape? It should be a portrait-only app.

I change the screen type using the virtual editor option for different inches of the screen. I can give you pictures to make a right idea about my problem. This is how it should look (on 5.4 inch screen): http://i.stack.imgur.com/Ph63x.png, and this is how it looks on a different screen (3.7 inche screen): http://i.stack.imgur.com/Ar2ZM.png

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Ah! I thought it was for the Crystal Ball app specifically. Paste in your layout code here and we'll take a look! Don't worry if it doesn't paste correctly; I'll format it. We use Markdown formatting for code (see the cheatsheet below), and XML can be tricky.

            <p><?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/mediib"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/editText24"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/editText13"
            android:layout_alignLeft="@+id/editText22"
            android:layout_alignRight="@+id/editText22"
            android:layout_below="@+id/editText22"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText25"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/editText14"
            android:layout_alignLeft="@+id/editText23"
            android:layout_alignRight="@+id/editText23"
            android:layout_below="@+id/editText23"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText33"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/editText34"
            android:layout_toRightOf="@+id/editText34"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText36"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/editText35"
            android:layout_alignRight="@+id/editText35"
            android:layout_toRightOf="@+id/editText33"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText32"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/editText37"
            android:layout_alignBottom="@+id/editText37"
            android:layout_alignLeft="@+id/editText38"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText34"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/editText32"
            android:layout_alignBottom="@+id/editText32"
            android:layout_toRightOf="@+id/editText32"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText35"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText37"
            android:layout_below="@+id/editText37"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText30"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/editText31"
            android:layout_below="@+id/editText34"
            android:layout_toRightOf="@+id/editText33"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editText29"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText34"
            android:layout_below="@+id/editText34"
            android:layout_toLeftOf="@+id/editText33"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText28"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/editText33"
            android:layout_toRightOf="@+id/editText29"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText31"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_above="@+id/editText30"
            android:layout_toRightOf="@+id/editText33"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText39"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText35"
            android:layout_alignRight="@+id/editText23"
            android:layout_below="@+id/editText38"
            android:layout_marginTop="41dp"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/medie"
            android:inputType="numberDecimal" />

        <EditText
            android:id="@+id/editText38"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/editText29"
            android:layout_alignBottom="@+id/editText29"
            android:layout_toRightOf="@+id/editText35"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText23"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/editText24"
            android:layout_alignLeft="@+id/editText38"
            android:layout_toLeftOf="@+id/editText29"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText27"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/editText23"
            android:layout_alignBottom="@+id/editText23"
            android:layout_alignLeft="@+id/editText35"
            android:layout_toLeftOf="@+id/editText38"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <Button
            android:id="@+id/bmedii3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText39"
            android:layout_alignRight="@+id/editText23"
            android:layout_below="@+id/editText39"
            android:textSize="12sp" />

        <EditText
            android:id="@+id/editText18"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText19"
            android:layout_alignRight="@+id/editText19"
            android:layout_below="@+id/editText1"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText26"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText18"
            android:layout_alignRight="@+id/editText18"
            android:layout_below="@+id/editText18"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText14"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText26"
            android:layout_alignRight="@+id/editText26"
            android:layout_below="@+id/editText26"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText13"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText24"
            android:layout_alignRight="@+id/editText14"
            android:layout_below="@+id/editText14"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText12"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/editText13"
            android:layout_below="@+id/editText13"
            android:layout_toRightOf="@+id/editText34"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText15"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText12"
            android:layout_alignRight="@+id/editText12"
            android:layout_below="@+id/editText12"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText16"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText15"
            android:layout_alignRight="@+id/editText15"
            android:layout_below="@+id/editText15"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText17"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText16"
            android:layout_alignRight="@+id/editText16"
            android:layout_below="@+id/editText16"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText1"
            android:layout_alignRight="@+id/editText1"
            android:layout_below="@+id/editText1"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText1"
            android:layout_alignRight="@+id/editText7"
            android:layout_below="@+id/editText7"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText1"
            android:layout_alignRight="@+id/editText5"
            android:layout_below="@+id/editText5"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText1"
            android:layout_alignRight="@+id/editText8"
            android:layout_below="@+id/editText8"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText1"
            android:layout_alignRight="@+id/editText3"
            android:layout_below="@+id/editText3"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText10"
            android:layout_alignRight="@+id/editText10"
            android:layout_below="@+id/editText10"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="60dp"
            android:layout_height="20dp"
            android:layout_above="@+id/editText17"
            android:layout_alignLeft="@+id/editText6"
            android:layout_alignRight="@+id/editText6"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignRight="@+id/editText32"
            android:layout_marginRight="29dp"
            android:layout_marginTop="120dp"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText37"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/bmedii2"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="80dp"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/editText23"
            android:layout_alignBottom="@+id/editText23"
            android:layout_alignRight="@+id/editText29"
            android:layout_toRightOf="@+id/editText23"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/editText4"
            android:layout_alignLeft="@+id/editText28"
            android:layout_alignTop="@+id/editText22"
            android:layout_toLeftOf="@+id/editText22"
            android:ems="10"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText22"
            android:layout_width="40dp"
            android:layout_height="20dp"
            android:layout_alignLeft="@+id/editText28"
            android:layout_alignRight="@+id/editText28"
            android:layout_below="@+id/editText29"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/nota"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText21"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/editText4"
            android:layout_alignRight="@+id/editText30"
            android:layout_alignTop="@+id/editText22"
            android:layout_toRightOf="@+id/editText22"
            android:ems="10"
            android:inputType="number"
            android:gravity="center"
            android:hint="@string/nota"
            android:background="@drawable/nota2" />

        <EditText
            android:id="@+id/editText19"
            android:layout_width="170dp"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/editText1"
            android:layout_alignBottom="@+id/editText1"
            android:layout_alignLeft="@+id/editText33"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/teze"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText20"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText16"
            android:layout_alignRight="@+id/editText17"
            android:layout_below="@+id/editText17"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/medie"
            android:inputType="numberDecimal" />

        <Button
            android:id="@+id/bmedii2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editText20"
            android:layout_alignRight="@+id/editText20"
            android:layout_below="@+id/editText20"
            android:textSize="12sp" />

        <EditText
            android:id="@+id/editText9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/bmedii2"
            android:layout_alignLeft="@+id/editText2"
            android:layout_alignRight="@+id/editText2"
            android:background="@drawable/nota2"
            android:ems="10"
            android:gravity="center"
            android:hint="@string/medie"
            android:inputType="numberDecimal" />

        <EditText
            android:id="@+id/editText41"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/editText9"
            android:layout_alignLeft="@+id/editText2"
            android:layout_alignRight="@+id/editText9"
            android:layout_below="@+id/editText2"
            android:ems="10"
            android:inputType="number"
            android:background="@drawable/nota2"
            android:gravity="center"
            android:hint="@string/nota" />

        <Button
            android:id="@+id/bmedii"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/editText37"
            android:layout_alignLeft="@+id/editText9"
            android:layout_alignRight="@+id/editText9"
            />

        <EditText
            android:id="@+id/editText40"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/editText22"
            android:layout_alignRight="@+id/editText30"
            android:layout_alignTop="@+id/editText22"
            android:layout_toRightOf="@+id/editText22"
            android:ems="10"
            android:inputType="number"
            android:background="@drawable/nota2"
            android:gravity="center"
            android:hint="@string/nota" />

    </RelativeLayout> </p>
            ``` 

Nothing so far?

Sorry for bothering you, but my membership trial period is going to expire, and I would like to know with it's worth to spent 49$ if I can learn something and If you can really help me, instead, I'm sorry.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

This post fell off my radar. Hopefully the info in my response to your other post can help you with this one, too. We as the staff can't spend too much time supporting personal projects like this, but hopefully we can get you on your way and get more students to help out.