Android Studio XML 小部件无法在设计器中正确呈现

Android Studio XML Widgets not rendering properly in designer

最近,在处理一些项目时,我在编写应用程序的用户界面时遇到了一个相当烦人的问题。问题是,某些控件(通常是浮动操作按钮或常规按钮)呈现得很奇怪。我很难准确解释 它的外观 - 但这里有一个示例,说明它如何在设计器中显示浮动操作按钮:

代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:baselineAligned="false"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:src="@drawable/ic_baseline_add_24"
        android:layout_height="wrap_content"/>


</LinearLayout>

现在,问题是,我没有添加任何奇怪或特殊的代码,XML 代码是最纯粹的,所以我不知道为什么我会遇到这些奇怪的渲染问题.

以下是它如何呈现以下按钮:

代码:

 <com.google.android.material.button.MaterialButton
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Submit"
      android:layout_gravity="bottom"
      android:textAllCaps="false"
      android:layout_margin="30dp"
      app:cornerRadius="30dp"
      android:id="@+id/submitButton"
      android:backgroundTint="@color/turquoise"
      />

图片:

将不胜感激!

干杯, 汤姆

解决方案很简单,您只需重新启动 android 渲染引擎。我为您的上下文提供了图像。在布局显示上方的 android 工作室右上角有 切换问题面板 单击它,您将在底部看到一个显示渲染问题的框 重新启动渲染engine,这将重新启动您的 android 工作室。你很高兴去。试试这个解决方案,让我知道您的问题是否已解决。

注意:在我的图像中,我已经重新启动了,所以没有重新启动渲染引擎的选项。但在你的 U 中可能会找到希望。

Image