【问题标题】:Rectangle shape as background causes black background作为背景的矩形形状导致黑色背景
【发布时间】:2015-08-28 19:13:34
【问题描述】:

我想在我的 RableRow 周围创建一个边框。 我使用以下形状作为背景。

bg_stroke_dotted_right

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list  xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:top="-4dp"
            android:left="-2dp"
            android:bottom="-4dp" 

            android:drawable="@drawable/stroke_dotted">
        </item>
    </layer-list>

stroked_dotted 可绘制对象

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
        <solid android:color="#000000" />
        <stroke
            android:dashGap="4dp"
            android:dashWidth="2dp"
            android:width="2dp"
            android:color="@color/greyDark" />

    </shape>

我不明白为什么使用“bg_stroke_dotted_right”作为 bg - 用黑色归档背景。 一旦我将“bg_stroke_dotted_right”添加为 bg - bg 就会变成黑色。

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_stroke_dotted_right"
            >

【问题讨论】:

标签: android layout background border


【解决方案1】:

在形状上试试这个:

<solid android:color="#00000000" />

在这种情况下,前 2 个“00”是颜色的 alpha,“00”表示透明。

享受吧!

【讨论】:

    【解决方案2】:

    公认的答案建议在实体元素中使用透明。由于这是导致错误的原因(在 android

    对于初学者而不是硬编码可以使用@android:color/transparent 的颜色,但最好使用@null,这样它就不会过度绘制。像这样的:

    <solid android:color="@null" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多