Androidアプリ:レイアウトの途中にスクロールを入れる
Androidアプリで以下のようなレイアウトを組む方法です。

weightSumを使う
上、中央、下のパーツに分けて、上下のパーツは固定、中央のパーツはスクロール可能にします。
最初にLinearLayoutをverticalで大外の枠をつくります。
それから上段と下段はLinearLayout、中央はScrollViewにします。
これらを比率で分割するには、親要素のLinearLayoutに
android:weightSum=”1″を設定します。
これにより、全体で1になるように比率を組むことができるようになります。
ここでは、最初のLinearLayoutはandoroid:layout_weight=”0.2″
中央のScrollViewはandroid:layout_weight=”0.7、
最後のLinearLayoutはandroid:layout_weight=”0.1″
のように設定してあります。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:weightSum="1"
android:layout_weight="0.2"
>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1"
>
<Button
android:id="@+id/q1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="------"
android:textSize="30sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
<Button
android:id="@+id/q2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="------"
android:textSize="30sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="0.1"
android:weightSum="1"
android:gravity="right"
>
<Button
android:id="@+id/help"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="0.2"
android:layout_marginRight="10dp"
android:text="help"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
関連記事