这里不允许元素形状

时间:2018-06-07 13:35:45

标签: android android-layout layout

我试图在我用作布局的XML中将一个shape元素放在一个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>

我收到消息&#34;此处不允许元素形状&#34;当我把鼠标放在&#34;形状&#34;。

1 个答案:

答案 0 :(得分:1)

Shape需要放在drawable文件夹中自己的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" />