忍者ブログ
  • 2025.01
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 2025.03
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2025/02/24 05:06 】 |
ScrollView
ScrollView
画面に収まりきらないサイズを表示したいときに使う。

ScrollView は垂直方向のスクロールのみできる。
HorizontalScrollView は水平方向のスクロールのみできる。
両方スクロールしたいときは…? 公式には用意されていない。別記事で。

以下はScrollView(垂直スクロール)に絞って説明する。


ScrollViewの直下には、Layoutしか配置できない。

使い方はとくに難しいことは無い。GraphicalLayoutでそのまま置いていけばよい。






<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.layoutmaster.MainActivity" >

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="70dp" スクロールするようにわざと小さめにしてるだけ
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="100dp"
android:layout_marginRight="142dp"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

</LinearLayout>

</ScrollView>

</RelativeLayout>





fillViewport
スクロールビューの中身(つまり直下のLayout)を、ScrollViewのサイズと同じに合わせるかどうか。ビューの中身がスクロールビューのサイズに対して小さいときに意味が出てくる。
trueかfalseで指定。デフォルトはfalse。つまり中身が少ないとビューが小さくなる。

android:fillViewport="false"の場合。(デフォルト)

ScrollViewのbackgroundを赤に、その子のLinearLayoutのbackgroundをシアンにしている。
中身が少ないので、LinearLayoutも小さい。

android:fillViewport="true"の場合。

LinearLayoutもScrollViewと同じサイズになっている。

PR
【2014/08/29 17:11 】 | Android | 有り難いご意見(0)
<<A valid provisioning profile for this executable was not found | ホーム | GridLayout>>
有り難いご意見
貴重なご意見の投稿














<<前ページ | ホーム | 次ページ>>