0

I want to have the following layout :

my layout

But when I run the code the first linear layout which contains a relative layout and an image is shown correctly. Then there is the "view pager" but it is not on the screen. and then there is a text box and a button which are there too.

So why my view pager is missing?

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical"
    tools:ignore="NestedWeights,ContentDescription" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="5" >

        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:src="@drawable/sp_page_name"
            tools:ignore="ContentDescription" />

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:padding="@dimen/product_views_horizontal_padding"
            tools:ignore="NestedWeights" >
        </RelativeLayout>
    </LinearLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager_sharepoint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/TODO"/>

    <TextView
        android:id="@+id/sharepoint_description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/sharepoint_description"
        tools:ignore="SelectableText" />
    <ImageButton 
        android:id="@+id/sp_more_info"
        android:layout_width="70dp"
        android:layout_height="30dp"
        android:background="@drawable/more_info_icon"
        android:layout_gravity="left"
        android:onClick="sp_more"/>

    </LinearLayout>
</ScrollView>
pbaris
  • 4,525
  • 5
  • 37
  • 61
ZahraZT
  • 49
  • 1
  • 1
  • 7

2 Answers2

0

The height of your ViewPager is android:layout_height="wrap_content".

So if your ViewPager doesn't contain other views, it won't be visible.

pbaris
  • 4,525
  • 5
  • 37
  • 61
0

Well, I found out that scrolling views do not work very good together. For my layout I solve the problem by changing the height and width of the viewpager to static sizes. Actually I defined some different sizes in my dimen.xml files for different screen sizes and use them for the height and width of my view pager. Here is the code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical"
    tools:ignore="NestedWeights,ContentDescription" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="5" >

        <ImageView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:src="@drawable/sp_page_name"
            tools:ignore="ContentDescription" />

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:padding="@dimen/product_views_horizontal_padding"
            tools:ignore="NestedWeights" >
        </RelativeLayout>
    </LinearLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager_sharepoint"
        android:layout_width="@dimen/viewpager_width"
        android:layout_height="@dimen/viewpager_height"
        android:contentDescription="@string/TODO"/>

    <TextView
        android:id="@+id/sharepoint_description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/sharepoint_description"
        tools:ignore="SelectableText" />
    <ImageButton 
        android:id="@+id/sp_more_info"
        android:layout_width="70dp"
        android:layout_height="30dp"
        android:background="@drawable/more_info_icon"
        android:layout_gravity="left"
        android:onClick="sp_more"/>

    </LinearLayout>
</ScrollView>
pbaris
  • 4,525
  • 5
  • 37
  • 61
ZahraZT
  • 49
  • 1
  • 1
  • 7