2014-01-03 2 views
0

Здесь я реализую фрагмент. Когда я помещаю свой fragmentBottomFragment под пейджером, его не отображает, но когда я пишу выше, это работает. Здесь я вставляя свой код XML:Фрагмент не отображается

<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> 
+0

Если один из ответов решил вашу проблему, вы должны принять ответ, чтобы помочь людям, которые имеют такую ​​же проблему в будущем. –

ответ

1

Высота relativeLayout, которая имеет ViewPager является match_parent так занимает все пространство в LinearLayout и ничего после этого выходит из экрана.

Попробуйте это:

<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> 
+0

попробуйте это, вы можете настроить вес в зависимости от вашего макета. –

+0

установить высоту до 0dp для всех просмотров –

0

Проблема заключается в том, что высота RelativeLayout установлен в match_parent. Вероятно, вы хотите, чтобы весь макет был RelativeLayout. Затем выровняйте каждый фрагмент сверху и снизу. Попробуйте что-то еще вот так:

<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> 
Смежные вопросы