LoginSignup
9
5

More than 5 years have passed since last update.

ScrollView内にConstraintLayoutを使用する際の注意点

Last updated at Posted at 2018-02-07

【概要】

LinearLayoutやFrameLayoutのようにConstraintLayoutもScrollViewの一番最初の子として追加することは可能です。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="arara.com.testcodestyle.MainActivity">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="長い文字列..."
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>
    </android.support.constraint.ConstraintLayout>

</ScrollView>

しかし、通常はこれでスクローリングできるのですが、作っているアプリでAndroidの設定からフォントサイズを変更した場合に、Constraint内のViewが重なり合ったような状態で表示されてしまう現象に遭遇しました。

【解決方法】

ようは、上記で言うところの、TextViewapp:layout_constraintBottom_toBottomOfparentだと駄目だというもの。

今回は、これを使ってmarginをセットしていたので、app:layout_constraintBottom_toBottomOfを削除して、ConstraintLayoutに対してpaddingをセットすることで対応しました。

ただ、上記のXMLではそもそも現象が再現しないので、「ScrollView内のConstraintLayoutに対してconstraintBottomでconstraintをつけた場合」というだけではなく、どうも再現には色々な条件があるようです・・・。

9
5
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
9
5