在Android XML中的可绘制对象周围出现奇怪的黑色边框

4

我正在为我的应用程序绘制自定义标题以输入信息。我在xml中绘制了2个形状,然后将它们定位在布局中。然后使用 <include> 将该布局放入我的主布局中。但是,在每个包含的标题周围画了一个黑色边框。这似乎只出现在api 21设备上。发生了什么?

circle.xml

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/icon_background"
    android:shape="oval">
    <padding
        android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp" />
    <solid
        android:color="@color/color_primary"
        android:angle="270">
    </solid>
</shape>

line.xml

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke android:width="5dp"
        android:color="@color/color_primary"/>

    <size android:height="10dp" />
</shape>

头部布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_height="5dp"
        android:layout_width="match_parent"
        android:layout_alignParentStart="true"
        android:layout_marginTop="14dp"
        android:src="@drawable/line">
    </ImageView>

    <ImageView
        android:id="@+id/circle"
        android:layout_height="32dp"
        android:layout_width="32dp"
        android:src="@drawable/circle"
        android:layout_centerHorizontal="true">
    </ImageView>

    <ImageView
        android:id="@+id/header_icon"
        android:layout_height="32dp"
        android:layout_width="32dp"
        android:src="@drawable/ic_action_car"
        android:layout_centerHorizontal="true">
    </ImageView>

</RelativeLayout>

包含布局

<RelativeLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/header_horizontal_margin"
        android:paddingRight="@dimen/header_horizontal_margin"
        android:paddingTop="@dimen/header_vertical_margin"
        android:paddingBottom="@dimen/header_vertical_margin">

        <include
            android:id="@+id/carSpecs"
            layout="@layout/header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </include>

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="@dimen/header_vertical_margin"
            android:paddingBottom="@dimen/header_vertical_margin"
            android:layout_gravity="center_horizontal"
            android:id="@+id/vehicleSpinner"
            android:layout_below="@+id/carSpecs"/> ...

Screenshot!


这是在所有设备上发生的吗?您在Android模拟器上进行过测试吗? - alanv
我在api21设备上注意到了这个问题。较低的api看起来没有问题。 - kd8bny
我无法在5.0.1模拟器或Nexus设备上复制您的示例XML。但是,我确实需要更改包含线条可绘制对象的ImageView的高度为wrap_content或10dp,以使可绘制对象正确适配。 - alanv
似乎第一个包含是正常的。但是当我重复使用相同的标题2次或更多次时,第二个和第三个将具有边框。 - kd8bny
3个回答

1

Remove this:

<stroke android:width="5dp"
    android:color="@color/color_primary"/>

来自 line.xml

这个操作会添加额外的“边框”,使用在你的 colors.xml 中定义的 color_primary 颜色资源。


1
我知道了!使用与@Der Golem相同的基础,我删除了

标签。
<size android:height="10dp" />

从line.xml文件中获取。由于笔画大小只有我接收到的边框大小的一半。感谢所有人的帮助!


1
尝试在你的line.xml中添加这个<solid android:color="#00FFFFFF"/>

不行,它仍然有边框。我注意到的一件事是,当我多次包含标题时,边框会显示出来。谢谢! - kd8bny

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接