【发布时间】: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