在椭圆内绘制一个矩形不会产生所需的结果

时间:2013-06-10 08:59:48

标签: android android-xml

我试图制作一个方形,其中方形应该在圆形内。它适用于带圆圈的正方形,但不是相反,我想知道为什么。到目前为止,这是我的xml代码:

<?xml version="1.0" encoding="utf-8"?>


<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:left="@dimen/tab_space" android:right="@dimen/tab_space">
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
        <size android:width="80dp" android:height="80dp" />
        <gradient android:angle="-90" android:startColor="#990000" android:endColor="#550000" />
        <stroke android:width="1dp" android:color="#110000" />

    </shape>
    </item>

    <item android:left="@dimen/tab_space" android:right="@dimen/tab_space">
        <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
            <size android:width="50dp" android:height="50dp" />
            <gradient android:angle="-90" android:startColor="#ff0000" android:endColor="#990000" />
            <stroke android:width="1dp" android:color="#440000" />
        </shape>
    </item>

</layer-list>

对此有何解决方案?

1 个答案:

答案 0 :(得分:1)

你可以试试这个。它对我有用。

chat_icon.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="oval">
        <padding android:left="7pt" android:top="8pt" android:right="7pt" android:bottom="8pt"/>
        <solid android:color="@android:color/white" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle">
        <stroke android:color="@color/jade" android:width="2dip"/>
        <solid android:color="@color/white" />
    </shape>
</item>

然后,要在布局中使用它,请按如下方式声明:

<ImageView
    android:id="@+id/chat_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/chat_icon"
    ------------------------------  />
相关问题