Search code examples
androidandroid-layoutandroid-scrollviewandroid-relativelayout

Scroll View is not working with relative layout


I tried to make a scroll view. However,it does not display the viewPager inside the scroll view. I don't know which part is wrong.

This is my xml file

<?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"
tools:context="com.example.qianonnphoon.tradeal.displaytrade.DisplayTradeActivity">

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

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabBackground="@drawable/tab_selector"
        app:tabGravity="center"
        app:tabIndicatorHeight="0dp">
        </android.support.design.widget.TabLayout>

    </android.support.v4.view.ViewPager>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="23dp"
    android:layout_below="@+id/view_pager"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:id="@+id/tvOwnItemName"/>
</RelativeLayout>
</ScrollView>

This is the output enter image description here

The viewPager is not displayed. The viewPager will be displayed only when I removed the scroll view


Solution

  • Add

    android:fillViewport="true"
    

    to scrollview and set scrollview height to

    android:layout_height="300dp"
    

    solve my problem.

    However, I dont know why the height cannot set as wrap_content