使用 XML drawable 的垂直线 [英] Vertical line using XML drawable

查看:46
本文介绍了使用 XML drawable 的垂直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何定义一条垂直线(1dp 粗)用作可绘制对象.

I'm trying to figure out how to define a vertical line (1dp thick) to be used as a drawable.

要制作一个水平的,非常简单:

To make a horizontal one, it's pretty straightforward:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
    <stroke android:width="1dp" android:color="#0000FF"/>
    <size android:height="50dp" />     
</shape>

问题是,如何使这条线垂直?

The question is, how to make this line vertical?

是的,有一些解决方法,例如绘制一个 1px 厚的矩形形状,但是如果它由多个 元素组成,这会使可绘制的 XML 变得复杂.

Yes, there are workarounds, such as drawing a rectangle shape 1px thick, but that complicates the drawable XML, if it consists of multiple <item> elements.

有人有这个机会吗?

更新

案件仍未解决.然而,对于 Android 文档运动中的任何人 - 您可能会发现这很有用:缺少 Android XML 手册

Case is still unsolved. However, For anyone on a Android documentation crusade - you might find this useful: Missing Android XML Manual

更新

除了我标记为正确的方法之外,我没有找到其他方法.虽然感觉有点沉重",但它确实有效,因此如果您碰巧知道答案,请不要忘记分享;)

I found no other way other than the one that I marked as correct. It does the trick though feels a bit "heavy", thus if you happen to know the answer don't forget to share ;)

推荐答案

您可以尝试使用 View 代替形状:

Instead of a shape, you could try a View:

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:background="#FF0000FF" />

我只将它用于水平线,但我认为它也适用于垂直线.

I have only used this for horizontal lines, but I would think it would work for vertical lines as well.

使用:

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#FF0000FF" />

用于水平线.

这篇关于使用 XML drawable 的垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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