我已经阅读了有关在 Android 中添加垂直线的其他问题,这是我的问题
- 我能够在我的主 RelativeLayout 下添加一条垂直线作为“ View ”,但在子 RelativeLayout 中无法添加。
垂直线的代码
<View
android:id="@+id/verticalSeperatorHours"
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="@color/medium_dark_gray"
/>
水平线的代码:
<LinearLayout
android:id="@+id/currentTimeMarkerLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="100dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="0dp" >
<View
android:layout_width="0dp"
android:layout_height="3dp"
android:layout_weight="1" />
<View
android:id="@+id/currentTimeLineView"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="14"
android:background="@color/strong_blue" />
</LinearLayout>
我的结构 xml:
- 相对布局
- 线性布局
- ScrollView
- 相对布局
- 相对布局
- “添加垂直线不起作用”
- “添加水平线有效”
- 线性布局
- 在这里添加垂直线可行,但不是我想要的"
水平线的LinearLayout之后的“View”没有出现。我意识到我没有深入了解 android 布局的结构,所以有人可以向我解释它是如何工作的。
完整布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:arm="http://schemas.android.com/apk/res/edu.cmu.sv.arm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="0dp" >
<LinearLayout ...
<View
android:id="@+id/dividerView"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/dayLabelsLinearLayout"
android:background="@color/medium_gray" />
<ScrollView
android:id="@+id/calendarScrollView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/dividerView"
android:layout_alignParentBottom="true"
android:overScrollMode="never"
android:padding="0dp"
android:scrollbars="none"
android:fadingEdge="none" >
<RelativeLayout
android:id="@+id/calendarRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp" >
<LinearLayout ...
<LinearLayout
android:id="@+id/currentTimeMarkerLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="100dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="0dp" >
<View
android:layout_width="0dp"
android:layout_height="3dp"
android:layout_weight="1" />
<View
android:id="@+id/currentTimeLineView"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="14"
android:background="@color/strong_blue" />
</LinearLayout>
<View
android:id="@+id/verticalSeperatorHours"
android:layout_width="1dip"
android:layout_height="match_parent"
android:layout_marginLeft="100dp"
android:background="@color/medium_dark_gray" />
</RelativeLayout>
</ScrollView>
<LinearLayout ...
<View ...
</RelativeLayout>
最佳答案
您应该在使用 View 之后完成 LinearLayout。
我在我的 XML 文件中使用了以下代码,它起作用了。
它应该也适合您。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:paddingLeft="5dip"
android:paddingRight="5dip">
<View
android:id="@+id/view"
android:layout_toRightOf="@+id/text1"
android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="#FF0000FF"/>
</LinearLayout>
关于Android "Add a vertical line"在 "RelativeLayout"/"Linear Layout",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18797263/