【问题标题】:Android Studio layout stuck emulating old version, does not reflect changes to designAndroid Studio 布局卡在模拟旧版本,不反映设计更改
【发布时间】:2021-03-01 04:00:43
【问题描述】:

我的 Android Studio 应用(决策者)编译时没有任何错误,并且按预期工作。但是,当我在手机上模拟甚至运行应用程序时,布局是我应用程序的旧版本。我对 activity_main.xml 所做的任何更改都不会在我运行应用程序时反映出来。

我正在运行最新版本的 AS:4.1.2

这里是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">

<Button
    android:id="@+id/addTopicBtn"
    style="@style/Widget.AppCompat.Button.Borderless"
    android:layout_width="158dp"
    android:layout_height="42dp"
    android:background="@color/colorPrimary"
    android:cursorVisible="false"
    android:fontFamily="@font/muli_bold"
    android:text="Add Topic"
    android:textColor="@android:color/background_light"
    app:layout_constraintBottom_toTopOf="@+id/chooseTopicBtn"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/selectedTopicText" />

<TextView
    android:id="@+id/selectedTopicText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@font/muli_bold"
    android:text="Topic"
    android:textSize="30sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.359" />

<Button
    android:id="@+id/chooseTopicBtn"
    style="@android:style/Widget.Material.Button.Borderless"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:fontFamily="@font/muli_bold"
    android:text="Button"
    android:textColor="@android:color/background_light"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintStart_toStartOf="parent"
    tools:targetApi="lollipop"
    tools:text="Choose Topic" />

<EditText
    android:id="@+id/addTopicText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:ems="10"
    android:fontFamily="@font/muli_bold"
    android:hint="add new topic"
    android:inputType="textPersonName"
    app:layout_constraintBottom_toBottomOf="@+id/chooseTopicBtn"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.576" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    tools:layout_editor_absoluteX="27dp"
    tools:layout_editor_absoluteY="45dp" />

<Switch
    android:id="@+id/switch1"
    android:layout_width="188dp"
    android:layout_height="50dp"
    android:text="Switch"
    tools:layout_editor_absoluteX="127dp"
    tools:layout_editor_absoluteY="119dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

这是实际的布局:

这是我运行它时的样子:

这是我迄今为止尝试过的:

-在 android studio 中创建了一个全新且不相关的项目并遇到了同样的问题。

-重启我的电脑

-重启AS

-使缓存无效/重新启动

-卸载/重新安装AS

-删除Program Files中的所有AS文件/文件夹

-删除C:\Users\Me中的.android文件夹

-从虚拟模拟器中擦除数据

-创建新的虚拟模拟器

-在实际手机上运行

-强制刷新布局

-启用与父级的自动连接

-禁用与父级的自动连接

非常感谢任何帮助解决这个问题。

【问题讨论】:

    标签: android android-studio android-layout kotlin layout


    【解决方案1】:

    问题是屏幕尺寸。使用 RelativeLayout 作为父布局或尝试在 Android Studio Preview 中使用的相同设备。

    【讨论】:

    • 我删除了xml文件并使用RelativeLayout创建了一个新文件,但它仍然显示旧布局并且没有显示任何更改。
    【解决方案2】:

    在尝试从头开始构建项目并尝试手动复制我的代码后,我发现 AS 创建了第二个正在使用的 activity_main.xml 文件。这可能是一个自动的建议,我在没有考虑或真正理解正在执行的操作的情况下点击了它。

    删除它会导致问题,所以我现在只使用第二个 xml 文件并且更改正在正常更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多