How do you make a LinearLayout scrollable?

前端 未结 10 1802
清歌不尽
清歌不尽 2020-11-28 18:55

I have lot of items on the screen and I need to use the scrollbar so the user can scroll down. However, the scroll is either not visible or it\'s not working. How is it poss

相关标签:
10条回答
  • 2020-11-28 19:10

    You need to wrap your linear layout with a scroll view

    <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>
    
    0 讨论(0)
  • 2020-11-28 19:18
     <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>
    
    0 讨论(0)
  • 2020-11-28 19:20

    You can add an atrribute in linearLayout : android:scrollbars="vertical"

    0 讨论(0)
  • 2020-11-28 19:28

    Here is how I did it by trial and error.

    ScrollView - (the outer wrapper).
    
        LinearLayout (child-1).
    
            LinearLayout (child-1a).
    
            LinearLayout (child-1b).
    

    Since ScrollView can have only one child, that child is a linear layout. Then all the other layout types occur in the first linear layout. I haven't tried to include a relative layout yet, but they drive me nuts so I will wait until my sanity returns.

    0 讨论(0)
提交回复
热议问题