简体   繁体   English

与设备不同的 Android Studio 预览

[英]Android Studio preview different from device

I'm trying to create two fragments.我正在尝试创建两个片段。 One that contains one spinner, and another that has the background changed when a color is selected from the spinner in the first fragment.一个包含一个微调器,另一个当从第一个片段中的微调器中选择一种颜色时背景发生了变化。 The functionality is there(seemingly) however I'm having difficulties with how it is actually appearing on screen.功能在那里(表面上)但是我对它实际出现在屏幕上的方式有困难。 Below are the attached photos, one of my device and one of the preview in android studio.下面是附上的照片,其中一张是我的设备,一张是在 android studio 中预览的。 The preview is obviously what I wish to be shown on my device.预览显然是我希望在我的设备上显示的内容。 It is also showing multiple spinner arrows, despite there being only one spinner.尽管只有一个微调器,但它也显示了多个微调器箭头。

错误的

想要的

activity_main.xml活动_main.xml

<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:id="@+id/paletteLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/container1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/container2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <Spinner
            android:id="@+id/colorSpinner"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/container2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/container1">

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

For those that are having a similar issue, you must create new layouts for the individual fragments.对于那些有类似问题的人,您必须为各个片段创建新的布局。 That's what I was failing to do.那是我没能做到的。 See https://developer.android.com/guide/components/fragments for more info.有关更多信息,请参阅https://developer.android.com/guide/components/fragments

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 预览和模拟器之间Android Studio中的布局不同 - Different layout in Android Studio between preview and emulator 使用与JAVA_HOME和Android Studio不同的Java版本的Android设备监视器 - Android device monitor using different java version from JAVA_HOME and Android Studio 私有设备与虚拟设备颜色不同 android studio - Different color on private device than virtual device android studio 将文件从android设备传输到android studio - Transfer file from android device to android studio 如何在 android 工作室中从服务器显示 fonts 的预览 - how to display preview of fonts from server in android studio Android Studio - 与预览版和模拟器相比,物理设备上的布局元素大小不同 - Android Studio - Layout Elements differ in size on the physical device, compared to the preview and emulator 在Android Studio中预览静态字符串? - Preview static strings in Android Studio? Android Studio 和我的设备中的分辨率相同,但外观不同 - Same resolution in Android Studio and my Device but different looks 在我的设备上运行的应用程序与预览版不同 - The app that runs on my device is different to the preview XML预览看起来与设备中的有所不同 - XML Preview looks different than in device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM