-1

I want to the first view fill the entire screen and when the user scrolls down the second view shows up but the ScrollView will not work!
I tried it with ConstraintLayout (this SO question), but it still does not work!

<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">
    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
            <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="1" />    
            </RelativeLayout>
            <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="2" />
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

How can I solve this?

zx485
  • 28,498
  • 28
  • 50
  • 59
beginner
  • 451
  • 1
  • 3
  • 14
  • possibly duplicate of https://stackoverflow.com/questions/2595063/android-horizontal-scrollview-behave-like-iphone-paging – kelalaka Sep 24 '18 at 18:56

1 Answers1

0

assume your first RelativeLayout in your scrollview is "view1". you should write a code like below example:

val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
val displayHeight = displayMetrics.heightPixels

view1.layoutParams.height = displayHeight
Reza.Abedini
  • 2,227
  • 2
  • 16
  • 18