2017-10-03 5 views
0

J'ai essayé de faire défiler la vue. Cependant, il n'affiche pas viewPager dans la vue déroulante. Je ne sais pas quelle partie est erronée.La vue de défilement ne fonctionne pas avec la disposition relative

Ceci est mon fichier xml

<?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> 

Ceci est la sortie enter image description here

Le viewPager n'apparaît pas. Le viewPager ne sera affiché que lorsque je l'ai enlevé la vue de défilement

Répondre

0

Ajouter

android:fillViewport="true" 

pour scrollview et définir la hauteur de scrollview à

android:layout_height="300dp" 

résoudre mon problème.

Cependant, je ne sais pas pourquoi la hauteur ne peut pas définir comme wrap_content

0

essayer ceci:

<ScrollView 
    android:id="@+id/scroll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="vertical"> 
    android:fillViewport="true" > 


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

</ScrollView> 
+0

Il affiche le viewPager quand j'ajoute Android: fillViewport = « true ». Cependant, ce n'est pas défilable. Je ne peux pas faire défiler vers le bas pour voir le texteVoir – phoon

+0

avez-vous écrit quelque chose dans le textview? –

+0

oui, je peux voir le texte avant d'ajouter Android: fillViewport = "true". – phoon

0

Essayez d'ajouter ce morceau de code avant de charger votre viewPager

NestedScrollView scrollView = (NestedScrollView) findViewById 
(R.id.nest_scrollview); 
scrollView.setFillViewport (true); 
+0

Le viewPager est affiché, mais ne peut pas faire défiler vers le bas – phoon