android - 此处不允许使用元素形状
问题描述
我试图在我用作布局的 XML 中的 LinearLayout 中放置一个形状元素。但是没有显示形状,我不知道如何得到这个。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView...>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:layout_marginLeft="5sp"
android:layout_marginStart="190sp"
android:layout_marginTop="25sp">
<solid android:color="#199fff"/>
<stroke
android:width="2dp"
android:color="#444444"/>
</shape>
</LinearLayout>
当我将鼠标放在“形状”上时,我收到消息“此处不允许元素形状”。
解决方案
Shape 需要放入它自己的 XML 文件中的drawable
文件夹中。然后您可以将该可绘制对象指定为视图的背景:
<View
android:layout_height="50dp"
android:layout_width="50dp"
android:background="@drawable/your_xml_name_here"
android:layout_marginLeft="5sp"
android:layout_marginStart="190sp"
android:layout_marginTop="25sp" />
推荐阅读
- mysql - 如何在 MySQL 中查找和插入丢失的数据而不创建重复数据
- kubernetes - 是否可以在 Mutating Webhook 中修改对象命名空间?
- c# - 与显式类型参数相比,使用“object”参数时的 C# NumSharp 未定义行为
- sql - 使用 declare table 运行聚合查询
- firebase - 将一组对象从 Firebase 映射到 List Flutter
- apache - 如何使用 xampp 为虚拟主机设置 IP 地址并通过 LAN 引导设备
- python - 如何在 pyCharm 中使用 pyinquirier
- java - 使用 TinyDB 时出现 NullPointerException
- php - WordPress如何通过functions.php排除某些类别
- regex - 使用正则表达式的最后一个单词的前 3 个字符?