要旨
Android のビュー上に、分割線やグリッドラインのような、画面上の固定位置に直線を引くのは、Viewを使い、「1dpの幅」だと垂直線、「1dpの高さ」だと水平線、とやるのが便利です。
以下、画面中央に垂直線・水平線を引くレイアウト設定です。
layout/activity_main.xml```
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:id="@+id/line_horizontal_center"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="visible"
android:background="@color/colorAccent"/>
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:id="@+id/line_vertical_center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
android:background="@color/colorPrimaryDark"/>
</android.support.constraint.ConstraintLayout>
参考資料
本投稿の元ネタです。この動画の投稿元の”CodingDemo" も役に立ちそうです。
Android のレイアウト要素の配置を決めるための制約 "constraintLayout" について詳しく説明しています。