布局在编辑器中看起来正确,在仿真器上错误

时间:2017-10-26 18:44:43

标签: android android-layout

我正在开发我的第一个Android项目 - 一个简单的活动应用程序本质上是信息性的。在Android工作室中,我将主题设置为素材灯光,我的Android布局将两个TextViews对齐。图1显示了它在Android Studio中的外观。但是,每当我在模拟器或Android设备上运行它时,我在图像2中得到以下内容。文本左对齐而右对齐,主题从白色变为紫色。

图片1 Android Studio LayOut Looks Right

图片2 Android Emulator / Device Looks Wrong

所以......发生了什么事?这是一个非常简单的应用程序。下面是我的布局的XML,以便于参考。

>

<?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>

编辑我的代码:

  

<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."
    />

1 个答案:

答案 0 :(得分:2)

将以下属性添加到左对齐的TextView

android:layout_alignParentRight="true"

同样,如果ActionBar的颜色与Android Studio中的颜色相似,则可以在styles.xml文件夹中进行更改,它们称为colorPrimary和{{1} }。