【问题标题】:Strange Black border around drawable android XML可绘制的android XML周围的奇怪黑色边框
【发布时间】:2015-01-19 18:26:12
【问题描述】:

我正在绘制自定义标题以在我的应用程序中输入信息。我在 xml 中绘制了 2 个形状,然后将它们放置在布局中。然后将该布局放入我的主布局中,使用 .但是,每个包含的标题周围都有一个黑色边框。这似乎只在 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"/> ...

【问题讨论】:

  • 所有设备上都会出现这种情况吗?你在安卓模拟器上测试过吗?
  • 我注意到它在 api21 设备上。较低的 api 似乎很好。
  • 鉴于您的示例 XML,我无法在 5.0.1 模拟器或 Nexus 设备上重现此内容。不过,我确实需要将包含可绘制线条的 ImageView 的高度更改为 wrap_content 或 10dp,以使可绘制对象正确匹配。
  • 似乎第一个包含很好。但是,当我重复使用相同的标题 2 次或更多次时,第二个和第三个将有边框。

标签: android xml android-layout android-drawable xml-drawable


【解决方案1】:

尝试在您的 line.xml 中添加此 &lt;solid android:color="#00FFFFFF"/&gt;

【讨论】:

  • 不,它仍然有边框。我注意到的一个问题是,当我多次包含标题时会显示边框。谢谢!
【解决方案2】:

删除这个:

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

来自line.xml

这是添加额外的“边框”,使用您的 colors.xml 中定义的 color_primary 颜色资源。

【讨论】:

    【解决方案3】:

    想通了!使用与@Der Golem 相同的基础,我删除了

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

    来自 line.xml。由于中风是我收到边框大小的一半。感谢大家的帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-08
      • 1970-01-01
      • 2018-06-07
      • 2019-01-26
      相关资源
      最近更新 更多