Android Studio XML 小部件无法在设计器中正确呈现 [英] Android Studio XML Widgets not rendering properly in designer
问题描述
最近,在处理一些项目时,我在编写应用程序的用户界面时遇到了一个相当烦人的问题.问题是,某些控件(通常是浮动操作按钮或常规按钮)呈现异常.我很难准确地解释它的如何 - 但这里有一个示例,说明它如何在设计器中显示浮动操作按钮的外观:
Recently, while working on some projects, I've had a rather annoying problem when coding the user interface of my application. The problem is, some controls (usually a floating action button or a regular button) render strangely. It's hard for me to explain exactly how it looks - but here's an example of how it shows the floating action button to look like in the 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 代码是纯粹的,所以我不知道为什么我会遇到这些奇怪的渲染问题.
Now, the thing is, I don't have any weird or special code added, the XML code is as pure as it gets, so I have no idea why I am having these strange rendering problems.
这是它呈现以下按钮的方式:
Here is how it rendered the following button:
代码:
<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 渲染引擎.我为您的上下文提供了 Image .在布局显示上方的android studio右上角有切换问题面板点击它,你会在底部看到一个显示渲染问题的框重启渲染引擎,这将重新启动你的安卓工作室.你很高兴去.试试这个解决方案,让我知道您的问题是否已解决.
Solution is simple u just need to restart your android rendering engine. I provided Image for your context . In android studio top right corner above layout display there is Toggle issue panel click on that and u will see one box in the bottom showing rendering issue restart rendering engine and that will restart your android studio. and u good to go. try this solution and let me know your issue is solved or not.
注意:在我的图像中,我已经重新启动,因此没有重新启动渲染引擎的选项.但在您的图像中,您可能会发现希望如此.
note: In my Image I already restarted so there is no option for restart rendering engine .but in yours's U may be find hope so.
这篇关于Android Studio XML 小部件无法在设计器中正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!