rupesh
rupesh

Reputation: 2891

Fragment is not displaying

Here i am implementing fragment. When i putting my fragmentBottomFragment below the pager its not displaying but when i am writing above this its working. Here i am pasting my xml code:

<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=".ProductDetails" >

<fragment
    android:id="@+id/fragmentTopFragment"
    android:name="com.test.abc.ProductDetailsTopFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
 </android.support.v4.view.ViewPager>
       </RelativeLayout>
 <fragment
    android:id="@+id/fragmentBottomFragment"
    android:name="com.test.abc.ProductDetailsBottomFragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</LinearLayout>

Upvotes: 0

Views: 86

Answers (2)

vipul mittal
vipul mittal

Reputation: 17401

Height of relativeLayout which has ViewPager is match_parent so it occupies all the space in linearlayout and anything after that goes out of screen.

Try this:

<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"
android:weightSum="3"
tools:context=".ProductDetails" >

<fragment
    android:id="@+id/fragmentTopFragment"
    android:name="com.test.abc.ProductDetailsTopFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp" android:layout_weight="1"/>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" android:layout_weight="1">

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
 </android.support.v4.view.ViewPager>
       </RelativeLayout>
 <fragment
    android:id="@+id/fragmentBottomFragment"
    android:name="com.test.abc.ProductDetailsBottomFragment"
    android:layout_width="wrap_content"
    android:layout_height="0dp" android:layout_weight="1" />
</LinearLayout>

Upvotes: 1

Mike Ortiz
Mike Ortiz

Reputation: 4041

The problem is that RelativeLayout's height is set to match_parent. You probably want the whole layout to be a RelativeLayout. Then align each fragment to the top and bottom. Try something more like this:

<RelativeLayout 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=".ProductDetails" >

<fragment
    android:id="@+id/fragmentTopFragment"
    android:layout_alignParentTop="true"
    android:name="com.test.abc.ProductDetailsTopFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_below="@id/fragmentTopFragment"
    android:layout_above="@+id/fragmentBottomFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

 <fragment
    android:id="@id/fragmentBottomFragment"
    android:layout_alignParentBottom="true"
    android:name="com.test.abc.ProductDetailsBottomFragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

Upvotes: 0

Related Questions