Jason Holt
Jason Holt

Reputation: 113

Layout looks right in Editor, wrong on Emulator

I'm working on my first Android project -- a simple one Activity app that is informational in nature. In the Android studio I have the theme setup to material light and I have my android Layout to align both TextViews to the right. Image one shows how it looks in Android Studio. However, whenever I run it in an emulator or on an Android device I get the following in Image 2. The text aligns left instead of right and the the theme changes from white to purple.

Image 1 Android Studio LayOut Looks Right

Image 2 Android Emulator / Device Looks Wrong

So... What's going on? It's a very simple app. Below is the XML for my layout for easy reference.

>

<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/appbg"
        />

    <TextView
        android:id="@+id/headingNumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:fontFamily="@font/abril_fatface"
        android:textSize="32sp"
        android:padding="16sp"
        android:layout_margin="8sp"
        android:text="JR's Pizza Call
        817-297-3000"
        android:textColor="#9e0f17"
         />

    <TextView
        android:id="@+id/mainTextInfo"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_below="@id/headingNumber"
        android:textAlignment="viewEnd"
        android:padding="16sp"
        android:layout_margin="16sp"
        android:text="For the best pizza in Crowley, Texas try JR's Pizza.  If you like pepperoni pizza, or pizza with the works, a supreme pizza, or a cheese pizza, JR's Pizza Crowley is here for you. If you like real beef hamburgers you've come to the right place. Or maybe you're in the mood for a fresh salad, pasta, or one of our delicious burritos, we have those on the menu too."
        />

</RelativeLayout>

Edited my code:

<TextView
    android:id="@+id/headingNumber"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:fontFamily="@font/abril_fatface"
    android:textSize="42sp"
    android:textAlignment="viewEnd"
    android:padding="16sp"
    android:layout_margin="8sp"
    android:text="JR's Pizza Call
    817-297-3000"
    android:textColor="#9e0f17"
     />

<TextView
    android:id="@+id/mainTextInfo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:textAlignment="viewEnd"
    android:layout_below="@id/headingNumber"
    android:padding="16sp"
    android:layout_margin="16sp"
    android:text="For the best pizza in Crowley, Texas try JR's Pizza.  If you like pepperoni pizza, or pizza with the works, a supreme pizza, or a cheese pizza, JR's Pizza Crowley is here for you. If you like real beef hamburgers you've come to the right place. Or maybe you're in the mood for a fresh salad, pasta, or one of our delicious burritos, we have those on the menu too."
    />

Upvotes: 2

Views: 472

Answers (1)

Xenolion
Xenolion

Reputation: 12735

Add the following attribute to the TextView that is aligned left:

android:layout_alignParentRight="true"

Also for the color of the ActionBar to look like the one in your Android Studio you can change it in the styles.xml folder,they are known as colorPrimary and colorPrimaryDark.

Upvotes: 2

Related Questions