- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我面临着在相对布局内绘制一条垂直线作为列表项布局的问题,如下所示:
layout 的高度会随着 item 的变化而变化,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="3dip"
android:layout_marginTop="3dip"
android:text="Button"></Button>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:text="TextView"></TextView>
<TextView android:id="@+id/expandable_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/button1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black"
android:text="Some expandable text"></TextView>
<View android:id="@+id/vertical_line"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="4dip"
android:background="@color/orange"/>
</RelativeLayout>
问题是垂直线不可见/不工作,有什么建议吗?
提前致谢!
附上
请注意,使用 LinearLayout 时,此问题已得到解决,但由于布局中的嵌套 View ,我遇到了性能问题,唯一的解决方案是使用 RelativeLayout,此外,TextViews 行在项目之间发生变化。
解决方案#1
经过一段时间的搜索,并使用了此处发布的建议答案(谢谢..)
我找到了一个解决方案,看起来很丑,但是由于填充问题
RelativeLayout 使用“fill_parent”高度,而布局高度本身设置为“wrap_content”,这似乎是一个合理的选择。
想法是采用最上面的 View (按钮)和最下面的 View (可扩展文本),并将它们用作与垂直线高度对齐的 anchor 。
正如您在这段代码中看到的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:paddingTop="3dip"
android:layout_marginTop="3dip"
android:text="Button"></Button>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:paddingTop="3dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:text="TextView"></TextView>
<TextView android:id="@+id/expandable_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/button1"
android:paddingBottom="10dip"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black"
android:text="Some expandable text"></TextView>
<View android:id="@+id/vertical_line"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/list_item_task_statusbutton"
android:layout_alignBottom="@id/list_item_task_description"
android:layout_marginRight="4dip"
android:background="@color/orange"/>
</RelativeLayout>
请注意 View 中的更改,尤其是“android:marginXXXX=value”的替换使用“android:paddingXXXX=value”来固定 View 位置。
谢谢.. 美好的一天!
最佳答案
好的,我遇到了同样的问题,花了一个小时才找到答案。您必须将 RelativeLayout
放入 LinearLayout
中。所以你的代码应该是这样的。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<View
android:id="@+id/drawerVerticalLine"
android:layout_width="10dip"
android:layout_height="fill_parent"
android:background="#7fa9c5"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:paddingTop="3dip"
android:layout_marginTop="3dip"
android:text="Button"></Button>
...
</RelativeLayout>
</LinearLayout>
</LinearLayout>
通过填充或对齐 drawerVerticalLine
,您将获得所需的结果。
关于android - 如何在可扩展内容 RelativeLayout 中绘制垂直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7136766/
我想在80个字符处添加一个标尺。我知道您可以add rulers to CodeMirror,但是我不知道是否应该将the corresponding javascript放在文件中的某个位置,或者放
我正在使用plotly包,并尝试向图形添加水平线。有什么办法使用plotly吗? 可以使用ggplot2和ggplotly函数完成此操作,如下所示: library(plotly) p % add
我想在 org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor 中的 120 个字符后显示一条垂直线(Eclipse 措辞中的打印边距)。这是否以某种方
我的想法是制作一个几乎像 Lollipop 一样的圆圈(在我的例子中是一个矩形)的底部有一条无限长的垂直线。我读到这可以使用 css :after 来完成,但是 psuedoelements 确实限制
我正在尝试使用 Bootstrap 在中间设置一 strip 有按钮的垂直线。 使用Bootstrap简单竖线:
我想知道如何用一条直线连接两个 div 元素,这条直线的距离有点像本网站中的那条线: JSFiddle link: https://jsfiddle.net/mcbvb8m2/ 对于水平和垂直 div
我有一个数字类型的输入,我应该将输入的值格式化为返回字符串的特定格式,因此作为解决方案,我添加了第二个字符串类型的输入并隐藏了输入 [type=number] 但用户只看到输入 [type=strin
我正在尝试创建一个教育时间表。应该有一条垂直线(红色)从“毕业帽”后面开始,然后穿过所有时间线后(绿色)。 这是我到目前为止得到的: .iconspace { position: relati
对于给定的矩形 R1 我试图找出哪些是可以与其相交的其他矩形 IF 我画了一个 vector 线段。 与 R1 相交的矩形标记为红色。 每个矩形都由其(top, left) 和(bottom, rig
我想知道是否可以激活悬停在图形上方的垂直线并突出显示点? 例如,在此图中:http://www.highcharts.com/stock/demo/compare ->将鼠标悬停在图形线上时,每个系列
我需要在我的图文上放置一 strip 有标签的垂直线,例如本例中的国庆节线 - http://www.fusioncharts.com/dev/chart-attributes.html?chart=
IE11不支持播放作品音频文件。这就是为什么我使用 ogv.js javascript库在IE11中播放它的原因。该库将音频数据流传输到IE11的内部Flash Player并进行播放。问题是在并行播
我在 android 中使用 achartengine 图形库制作折线图。有人可以建议我放置十字准线(当用户触摸图表时在所有数据点上移动的垂直线)我的要求符合这样的实现 http://www.jqch
我正在为子菜单项制作 TreeView ,我快完成了。最后一个元素的问题,现在看起来如何: 我想看起来像: DEMO HTML: Example 1
如何像此处那样在我的网页边框周围创建边框? http://www.callieschweitzer.com/ 我尝试做一条水平线,但很难将其与垂直线对齐……不过我觉得有一种更简单的方法。有什么想法吗?
这个问题在这里已经有了答案: What does the vertical pipe ( | ) mean in C++? (4 个答案) 关闭 5 年前。 我用了双竖“||”作为 bool “或”
我使用 Pandoc (http://johnmacfarlane.net/pandoc/README.html) 及其 Markdown 处理器。当我使用 Pandoc 将下面的网格转换为 PDF(
谁能告诉我如何扩展 Chart.js v2.0。我需要折线图中的垂直线,我想实现类似于 http://jsfiddle.net/dbyze2ga/ 的东西. Chart.types.Line.exte
我已经创建了一个自定义通知 XML 文件。我想画一条垂直线,就像下图中的水平线一样。我一直在尝试各种方法无法实现它。 xml 中从水平到垂直的方向对我没有帮助。 查看下面的屏幕截图:我想要垂直线而不是
如何使用标准图像处理过滤器(来自 OpenCV)从图像中去除长水平和垂直线? 图像是黑白的,所以删除意味着简单地涂成黑色。 插图: 我目前正在用 Python 执行此操作,遍历像素行和列并检测连续像素
我是一名优秀的程序员,十分优秀!