2015-07-11 66 views
0

我添加ViewPager()到佈局(根是RelativeLayout) 問題是如果我試圖保持根,以便我可以滑動屏幕,但Viewpager的內容不是可見,無需添加滾動查看它顯示的內容。ViewPager添加滾動視圖到佈局後不工作

我的代碼activity_profile.xml

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


     <ImageView 
      android:id="@+id/header_imageview" 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:adjustViewBounds="true" 
      android:scaleType="centerCrop" 
      android:src="@drawable/header" /> 

     <LinearLayout 
      android:id="@+id/informations_container" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/header_imageview" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:paddingBottom="32dp" 
      android:paddingTop="32dp" 
      android:weightSum="1"> 


      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Test Header" 
       android:textSize="17dp" 
       android:textStyle="bold" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="4dp" 
       android:gravity="center" 
       android:text="Doctor Certificate" 
       android:textColor="#FF707070" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="8dp" 
       android:text="2nd line description" 
       android:textColor="#FF909090" /> 

      <net.thrymr.mednetwork.SlidingTabLayout 
       android:id="@+id/sliding_tabs" 
       android:layout_width="15dp" 
       android:layout_height="0dp" 
       android:layout_weight="0.20" 
       android:background="?attr/colorPrimaryDark" /> 

     </LinearLayout> 


     <ImageView 
      android:layout_width="75dp" 
      android:layout_height="75dp" 
      android:layout_above="@+id/informations_container" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="-16dp" 
      android:src="@mipmap/ic_launcher" /> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/informations_container" 
      android:orientation="vertical"> 


      <net.thrymr.mednetwork.SlidingTabLayout 
       android:id="@+id/sliding_tabs_profile" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="?attr/colorPrimaryDark" /> 

      <android.support.v4.view.ViewPager 
       android:id="@+id/pager" 
       android:layout_width="match_parent" 
       android:layout_height="0px" 
       android:layout_weight="0.24" 
       android:background="@android:color/white" /> 

     </LinearLayout> 


    </RelativeLayout> 
</ScrollView> 

ProfileActivty.java

mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); 
    mViewPager = (ViewPager) findViewById(R.id.pager); 
    mViewPager.setAdapter(mAppSectionsPagerAdapter); 

    slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs_profile); 
    // mViewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), titles)); 
    slidingTabLayout.setViewPager(mViewPager); 
    slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { 
     @Override 
     public int getIndicatorColor(int position) { 
      return getResources().getColor(R.color.accentColor); 
     } 
    }); 
+0

什麼是您的日誌貓錯誤 – koutuk

+0

沒有錯誤...只是它不顯示 –

回答

0

我想同樣的事情了一段時間回來,我記得有此相同的問題。

您需要將android:fillViewport="true"添加到ScrollView元素,一切都將完美。

+0

這是否解決了您的問題? –

+0

你的意思是我必須將其添加到根元素中。 –

+0

是的,我已經更新了答案。請檢查。 –