gpt4 book ai didi

android - 布局在编辑器中看起来正确,在模拟器上错误

转载 作者:搜寻专家 更新时间:2023-11-01 09:31:24 25 4
gpt4 key购买 nike

我正在开发我的第一个 Android 项目 - 一个简单的 Activity 应用程序,本质上是信息性的。在 Android 工作室中,我将主题设置为 Material 光,并且我的 android 布局将两个 TextView 对齐到右侧。图一显示了它在 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."
/>

最佳答案

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

android:layout_alignParentRight="true"

此外,要使 ActionBar 的颜色看起来像您 Android Studio 中的颜色,您可以在 styles.xml 文件夹中更改它,它们被称为 colorPrimarycolorPrimaryDark

关于android - 布局在编辑器中看起来正确,在模拟器上错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46961663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com