[英]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.