如何在视图的一侧创建边框?
我发现要在视图周围添加边框,我可以使用以下代码作为视图的背景:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#999999" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
但是如果我只想要底部、顶部、右侧或左侧的边框怎么办?我尝试了以下操作:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:color="#000"/>
</shape>
但是当我将其设置为背景时,
android:background="@drawable/my_border"
它会在视图中间绘制线条,因此我有删除线效果。有什么办法可以在底部或顶部绘制这条线或使其垂直吗?
在 WPF 中,我们有形状的相对坐标,因此我可以根据需要偏移线条。安卓上有类似的东西吗?如果我们没有边框,至少我们应该有好的线条形状绘制工具,这样我们就可以根据需要绘制边框。 Android 开发者是否计划对此采取行动?
I have found that to add borders around views I can use the following code as a background for the view:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#999999" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
But what if I want a border just for bottom, or top or right or left? I tried the following:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:color="#000"/>
</shape>
but when I set it as background
android:background="@drawable/my_border"
it draws the line at the middle of the view, so I have a strike-through effect. Is there any way I can draw this line at the bottom or at the top or make it vertical?
In WPF we have a relative coordinates for shapes, so I can offset lines as needed. Is there something similar on Android? If we don't have borders, at least we should have good line shape drawing tools, so we can draw borders as needed. Do Android developers plan to do something about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于视图顶部或底部的边框线,您可以在此处查看我之前的答案。这是一个非常简单的方法。
For border line on the top or bottom of you view, you can check my previous answer here. It is a very simple way.
你在寻找这个吗:
它只会在右侧显示边框。你必须将其设置为背景
Are u looking for this:
it will show a border only at the right. And u have to set it as the background