Android Studio 在模拟器中显示不同的设计

蒂鲁玛莱 KG

这是我在Android Studio中设计的[设计][1]

在模拟器中显示如下 [Emulator][2]

代码:activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:text="@string/app_name"
        app:layout_constraintHeight_percent="0.1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintWidth_percent="0.3"
        tools:text="Happy Birthday Thirumalai"
        tools:visibility="visible" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:text="@string/family"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.1"
        app:layout_constraintWidth_percent="0.3"/>
</androidx.constraintlayout.widget.ConstraintLayout>

代码:AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.happybirthday">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.HappyBirthday">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

我该如何解决这个问题?谢谢你 !![1]:https : //i.stack.imgur.com/dQn8s.png [2]:https : //i.stack.imgur.com/8hJAa.png

托尼

问题是您的命名空间。

为了显示文本只是为了查看它在设计过程中的显示方式,我们使用tools:text命名空间。要在模拟器或 Android 设备上显示实际文本,我们使用android:text.

在此处输入图片说明

您还可以看到设计属性的差异。

在此处输入图片说明

所以你需要做的是使用android:text命名空间

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:text="Happy Birthday Thirumalai"



        android:layout_marginLeft="16dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:text="@string/family"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginRight="16dp" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

风景模式Android Studio中模拟器不工作?

Linux中的Android Studio模拟器错误

无法在Android Studio 2.0中启动模拟器

如何在Android Studio中更改目标模拟器?

Android Studio中的模拟器无法启动

SD卡(在AVD中创建)在Android Studio的模拟器中显示为“已删除”

Visual Studio Android模拟器显示键盘

模拟器无法在Android Studio 2.0中运行

无法在模拟器Android Studio中启动AVD

Android Studio图片显示在设计视图中,但不显示在模拟器中

无法在Android Studio中启动模拟器

模拟器在Android Studio中已过时错误

如何在Android Studio模拟器中禁用Crashlytics

从Android Studio中的模拟器访问Localhost和Virtualhost?

在Android Studio的模拟器中触及白屏

更新android studio 3.3中的Android模拟器失败

Android Studio模拟器阻止我的应用显示

在“适用于Android的Visual Studio模拟器”中启动后,Visual Studio 2019为什么不显示该模拟器?

如何在模拟器Android Studio中设置密度

Android Studio-imageView在设计编辑器中显示图像,但不在模拟器或设备上显示

项目列表布局显示在Android Studio中,但不在模拟器中显示

Android Studio的模拟器?

Android Studio中的模拟器控件在哪里

Android Studio中的模拟器

为什么Android Studio中的设计预览与Android模拟器中的渲染UI之间存在布局差异?

模拟器未显示在Android Studio中

在Android Studio中运行模拟器时出错

Android Studio 的 AVD 中的模拟器无法正确启动

Android 模拟器在 Android Studio 中启动,但未显示在设备选项卡中