260

画面にたくさんのアイテムがあり、ユーザーが下にスクロールできるようにスクロールバーを使用する必要があります。ただし、スクロールが表示されないか、機能していません。スクロールバーをに追加するにはどうすればよいLinearLayoutですか?

4

10 に答える 10

481

線形レイアウトを<ScrollView>

例については、こちらをご覧ください。

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       xmlns:android="http://schemas.android.com/apk/res/android">
       <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <LinearLayout 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:orientation="vertical">
                  <!-- Content here -->
            </LinearLayout>
      </ScrollView>
 </LinearLayout>

注:APIレベル8以降では、 fill_parentは非推奨になり、match_parentに名前が変更されました。

于 2010-10-29T20:17:04.870 に答える
152
<ScrollView 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/scroll" 
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <LinearLayout 
            android:id="@+id/container"
            android:orientation="vertical" 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
      </LinearLayout>

 </ScrollView>
于 2010-10-30T04:16:02.710 に答える
6

線形レイアウトをスクロールビューでラップする必要があります

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout 
        android:id="@+id/container" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


    </LinearLayout>
</ScrollView>
于 2020-11-06T07:03:17.020 に答える
4

これが私が試行錯誤してやった方法です。

ScrollView - (the outer wrapper).

    LinearLayout (child-1).

        LinearLayout (child-1a).

        LinearLayout (child-1b).

ScrollViewは子を1つしか持つことができないため、その子は線形レイアウトです。次に、他のすべてのレイアウトタイプが最初の線形レイアウトで発生します。私はまだ相対的なレイアウトを含めようとはしていませんが、それらは私を狂わせるので、私の正気が戻るまで待ちます。

于 2013-03-28T00:18:48.177 に答える
4

これは、タグを使用して実行できます<ScrollView>ScrollViewの場合、注意しなければならないことの1つは、ScrollViewには1つの子が必要です。

完全なレイアウトをスクロール可能にする場合<ScrollView>は、上部に追加します。以下の例を確認してください。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout 
        android:id="@+id/container" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
            <!-- Content here -->
    </LinearLayout>

</ScrollView>

ただし、レイアウトの一部をスクロール可能にする<ScrollView>場合は、その部分に追加します。以下の例を確認してください。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="400dp">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
                <!-- Content here -->
        </LinearLayout>

    </ScrollView>

</LinearLayout>
于 2017-06-09T03:36:47.610 に答える
1

ScrollViewをレイアウトファイルの最初の子として配置し、その中にlinearlayoutを配置する必要があります。これで、Androidは、利用可能なコンテンツとデバイスサイズに基づいて、スクロール可能かどうかを決定します。

ScrollViewは複数の子を持つことができないため、linearlayoutに兄弟がないことを確認してください。

于 2017-01-02T09:01:50.647 に答える
1

次の属性を使用して、線形レイアウトで囲む必要があります

<LinearLayout ...>
<scrollView ...> 

</scrollView>
</LinearLayout>
于 2018-02-03T19:03:21.357 に答える
0
 <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">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <---------Content Here --------------->
            </LinearLayout>
       </ScrollView>
    </LinearLayout>
于 2016-05-07T19:07:29.710 に答える
0

レイアウトをスクロール可能にしたいときはいつでも<ScrollView>、レイアウトまたはコンポーネントをその中に使用できます。

于 2020-11-06T07:33:51.420 に答える
-29

linearLayoutに属性を追加できます:android:scrollbars="vertical"

于 2010-10-30T04:18:48.147 に答える