如何绘制边界上的线性布局只是一面? [英] How to draw border on just one side of a linear layout?

查看:105
本文介绍了如何绘制边界上的线性布局只是一面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够画出边框线性布局,但它是越来越吸取各方关注。我只想把它限制在右边,就像你在CSS做(右边框:1px的固体红色​​)。

I'm able to draw border to a linear layout, but it is getting drawn on all sides. I want to restrict it to right side only, like you do in CSS (border-right:1px solid red;).

我想这一点,但它仍然吸引各方:

I've tried this, but it still draws on all sides:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape android:shape="rectangle" >
        <stroke
            android:height="2dp"
            android:width="2dp"
            android:color="#FF0000" />

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

        <padding
            android:bottom="0dp"
            android:left="0dp"
            android:right="1dp"
            android:top="0dp" />

        <corners
            android:bottomLeftRadius="0dp"
            android:bottomRightRadius="5dp"
            android:radius="1dp"
            android:topLeftRadius="5dp"
            android:topRightRadius="0dp" />
    </shape>
</item>

这是如何做到这一点有什么建议?

Any suggestions on how to accomplish this?

顺便说一句,我不希望使用推杆宽度1DP的景色所要求的一侧的黑客。

BTW, I do not want to use the hack of putting a view of width 1dp on the required side.

推荐答案

您可以使用它来得到边界一侧

You can use this to get border on one side

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="#FF0000" />
    </shape>
</item>
<item android:left="5dp">
    <shape android:shape="rectangle">
        <solid android:color="#000000" />
    </shape>
</item>
</layer-list>

EDITED

由于很多,包括我想和透明背景的一侧边缘,我实现了一个 BorderDrawable 这可以给我用不同的大小和颜色边框以同样的方式当我们使用CSS。但是,这无法通过XML使用。为了支持XML,我添加了一个 BorderFrameLayout 中,你的布局可以包裹。

As many including me wanted to have a one side border with transparent background, I have implemented a BorderDrawable which could give me borders with different size and color in the same way as we use css. But this could not be used via xml. For supporting XML, I have added a BorderFrameLayout in which your layout can be wrapped.

请参阅我的 github上,在完整的源代码。

See my github for the complete source.

这篇关于如何绘制边界上的线性布局只是一面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆