4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android レイアウトで直線を描画する方法

Posted at

要旨

Android のビュー上に、分割線やグリッドラインのような、画面上の固定位置に直線を引くのは、Viewを使い、「1dpの幅」だと垂直線、「1dpの高さ」だと水平線、とやるのが便利です。

以下、画面中央に垂直線・水平線を引くレイアウト設定です。

layout/activity_main.xml

<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">


android:background="@color/colorPrimaryDark"/>


スクリーンショットです。
![Screenshot_20190322-004107.png](https://qiita-image-store.s3.amazonaws.com/0/211499/e550a439-2aac-f436-73ff-f454efe448e1.png)

## 参考資料

* [Android Divider - How to Draw Vertical And Horizontal Lines](https://www.youtube.com/watch?v=SqnzChkVyyM)

本投稿の元ネタです。この動画の投稿元の”CodingDemo" も役に立ちそうです。

* [XMLで始めるConstraintLayout](https://qiita.com/nakker1218/items/0faa8c1ab504cc4cedea)

Android のレイアウト要素の配置を決めるための制約 "constraintLayout" について詳しく説明しています。
4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?