【问题标题】:Android Studio XML Widgets not rendering properly in designerAndroid Studio XML 小部件无法在设计器中正确呈现
【发布时间】:2021-06-20 08:52:45
【问题描述】:

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

代码:

<?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 studio。
  • @danialiranpour 谢谢你的回复——我都试过了,但最终都失败了。什么都没有改变。
  • 我不知道,我之前遇到过这个问题,但我是这样解决的。这很奇怪。
  • @danialiranpour 如果我没有得到解决方案,我明天会赏金 - 这让我很困扰
  • 我也遇到这个问题有一段时间了,好像没有办法解决。

标签: android android-studio android-layout android-xml


【解决方案1】:

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

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

Image

【讨论】:

    猜你喜欢
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    • 2019-05-30
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    相关资源
    最近更新 更多