7Rアプリ

プログラミングで詰まったことなど書いてます

this view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint レイアウトの対処方法 ConstraintLayoutの場合

起きていること

 

<TextView の部分に エラーの線が引かれている。

 

f:id:kobearen:20190602090339p:plain

Text view

出ているエラー this view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint

このビューは垂直方向に拘束されていません。垂直方向の拘束を追加しない限り、実行時に上部にジャンプします。

 

 

 

デバッグすると、ボタンやテキストの配置がぐちゃぐちゃ

 

f:id:kobearen:20190602090415p:plain

Android ボタンの配置

 

レイアウトの対処と対処方法

 垂直的な指標が有りません

とのことなので、constraintTop_toTopOfとconstraintBottom_toBottomOfconstraintBottom_toBottomOf

をつけてあげると赤線が消えて無事に解決しました。

 

ConstraintLayoutの場合、縦横の要素が必ず必要なようです。
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

 位置調整を行う際は

app:layout_constraintHorizontal_bias="0.3"

を追加する。

HorizontalやVerticalは臨機応変に変更する

 

app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.5"

 

 

 

レイアウトの基礎を参考にしたサイト

https://qiita.com/mii-chang/items/ee965c1e8826d4e59414 

 

padding

f:id:kobearen:20190602122017p:plain

paddng