2022-03-18
androidのアプリを作っているとどうしても要素が多くなってきて縦長になってしまう
時があります。
今使っているrelativeLayoutはデフォルトではスクロール機能がついておらず、今回のお題の
scrollviewというコンポーネントを付けないとスクロールしてくれないみたいです。
さてscrollviewの使い方ですが、単純明快超シンプルでスクロールしたいレイアウトを
<scrollview></scrollview>で囲むだけ。
</pre> <android.support.constraint.ConstraintLayout 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" android:background="#C0C0C0" <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/scrollView"> <RelativeLayout android:id="@+id/relativeLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="MissingConstraints"> //ここにレイアウトを入れていく </RelativeLayout> </ScrollView> </android.support.constraint.ConstraintLayout> <pre>
未だレイアウトに手を焼いている自分でもさくっと使えたのでlinearlayoutや
relativelayoutでレイアウトを構築している方にはおすすめです。
最後に自分はレイアウト作成はxmlで書いているのですが、ConstraintLayoutで普通に制約バリバリつけて自由に
レイアウト作っている人を見ると本当に尊敬します。柔軟なレイアウトが作れる
魔法使いになれるよう力を付けたいと思います・・・。