1

Here is my problem. I have an include layout in my home page for say. I want to make it scroll because to long to put. I had add scrollview before the constraint layout of my home xml which where I include my other layout. I have search and all of the solution not work in my case

I have add scrollview and nested scroll view, and add fillViewPort attribute to true. But it just didn't work.

This XML code is in fragment by the way. Forget to add that.

Here is my XML home layout code

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    tools:context=".HomeFragment"
    >

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".HomeFragment">

    <!-- TODO: Update blank fragment layout -->

    <!--<Button-->
    <!--android:layout_width="match_parent"-->
    <!--android:id="@+id/to_web"-->
    <!--android:layout_height="wrap_content" />-->


    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:background="@drawable/border_style"
        android:backgroundTint="@color/colorPrimaryDark"
        android:text="@string/btn_ow"
        android:textColor="@color/white"
        app:layout_constraintEnd_toStartOf="@+id/button3"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:background="@drawable/border_style"
        android:text="@string/btn_rt"
        app:layout_constraintEnd_toStartOf="@+id/button4"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/button2"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:background="@drawable/border_style"
        android:text="@string/btn_mc"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/button3"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/to_sr"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="8dp"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:fontFamily="@font/open_sans"
        android:text="@string/btn_cari"
        android:textColor="@android:color/background_dark"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button3"
        app:layout_constraintVertical_bias="0.0"
        android:visibility="gone"/>

    <include
        android:id="@+id/ow_ly"
        layout="@layout/one_way_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button3" />
    <include layout="@layout/round_trip_layout" android:id="@+id/rt_ly" android:visibility="gone"/>
    <include layout="@layout/multi_city_layout" android:id="@+id/mc_ly" android:visibility="gone"/>


</android.support.constraint.ConstraintLayout>

</ScrollView>

1 Answers1

0

I've used a scrollview for some time. In my opinion you need to set the scrollview within your layout. So add you scrollview into the constrainLayout. If this doesn't work. I usually use a linearLayout this is easier to use.

I'll hope this will help you with you problem!

Dedmen7
  • 9
  • 3