【问题标题】:custom border for ImageViewImageView 的自定义边框
【发布时间】:2015-12-31 11:28:08
【问题描述】:

我想从内部去除桃色纯色,只希望它位于顶部、左侧和右侧的边界。底部颜色红色很好。我到处搜索,但他们只建议使用纯色来覆盖整个红色边框。

XML 代码

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <!-- Draw a 2dp width border around shape -->
            <stroke
                android:color="#ff1e0c"
                android:width="2dp"
                />
        </shape>
    </item>
    <!-- Overlap the left, top and right border using background color  -->
    <item
        android:bottom="2dp"
        >
        <shape android:shape="rectangle">
            <solid android:color="#fffbce"/>
        </shape>
    </item>

</layer-list>

【问题讨论】:

  • 你能说明一下实际上需要这个吗?
  • 我想做这样的层imgur.com/DQt8arf
  • 如果您使用的是 tab-host,那么您可以轻松添加分隔符,它也会影响您的需要
  • 不使用 tabhost。只是 LinearLayout @Survivor 中的 ImageView。

标签: android xml layer-list


【解决方案1】:

试试这个解决方案,

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

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- This is the line -->
    <item android:bottom="1dp">
        <shape>
            <solid android:color="#00000000" />
            <stroke
                android:width="1dp"
                android:color="#FF0000" />
        </shape>
    </item>
    <item
        android:bottom="-1dp"
        android:left="0dp"
        android:top="0dp">
        <shape>
            <solid android:color="#00000000" />
            <stroke
                android:width="1dp"
                android:color="#000000" />
        </shape>
    </item>


</layer-list>

【讨论】:

  • 代码将整个边框颜色更改为红色@Amit。
  • 这里你会得到底部的红色和其他三个侧面的黑色,这就是你想要的对吧? @山姆
  • 是的,我明白了,但它看起来不太好,因为底部还有一些黑色。此外,如果我增加红色的 dp,它不会增加,它只会跳到比底部黑色边框更高的水平。 @Amit
  • 我认为更好的选择是使用 View 之类的东西,并在单击 ImageView 时更改它的颜色。
  • 增加 dp 时的红色不会改变,因为它在黑色上过度疲劳。所以我认为这是你想要的 xml 边框的最佳解决方案。 @山姆
猜你喜欢
  • 2012-11-09
  • 1970-01-01
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多