2017-08-29 78 views
0

我有這樣的佈局Android viewpager沒有顯示?

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <ImageView 
      android:id="@+id/header_cover_image" 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:scaleType="centerCrop" 
      android:background="@color/com_facebook_button_background_color_pressed" /> 
     <refractored.controls.CircleImageView 
      android:id="@+id/imageProfile" 
      android:layout_width="120dp" 
      android:layout_height="120dp" 
      android:layout_below="@+id/header_cover_image" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="-60dp" 
      android:layout_gravity="center_horizontal" 
      android:elevation="5dp" 
      android:padding="20dp" 
      android:scaleType="centerCrop" /> 
     <RelativeLayout 
      android:id="@+id/profile_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/header_cover_image" 
      android:background="#ebca0707" 
      android:elevation="4dp" 
      android:paddingBottom="24dp"> 
      <ImageView 
       android:id="@+id/add_friend" 
       android:layout_width="30dp" 
       android:layout_height="30dp" 
       android:layout_marginLeft="16dp" 
       android:layout_marginTop="16dp" 
       android:src="@drawable/played" /> 
      <ImageView 
       android:id="@+id/drop_down_option_menu" 
       android:layout_height="30dp" 
       android:layout_alignParentRight="true" 
       android:src="@drawable/wins" 
       android:layout_width="30dp" 
       android:layout_toLeftOf="@+id/drop_down_option_menu" 
       android:layout_marginRight="16dp" 
       android:layout_marginTop="16dp" /> 
      <TextView 
       android:id="@+id/user_name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="76dp" 
       android:textColor="#fff" 
       android:textSize="24sp" 
       android:textStyle="bold" /> 
      <TextView 
       android:id="@+id/userStatus" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/user_name" 
       android:text="Status" 
       android:textColor="#fff" 
       android:textSize="14sp" 
       android:layout_marginLeft="16dp" 
       android:layout_marginTop="15dp" 
       android:layout_centerHorizontal="true" /> 
     </RelativeLayout> 

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

     <android.support.design.widget.TabLayout 
      android:id="@+id/tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/profile_layout" 
      android:elevation="6dp" 
      android:background="?android:attr/colorPrimary"/> 

     <android.support.v4.view.ViewPager 
       android:id="@+id/pager" 
       android:layout_below="@+id/tab_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 
    </RelativeLayout> 

</ScrollView> 

最後的LinearLayout顯示選項卡,但是當我切換他們沒有viewpager數據任何責任。我嘗試了tablayout創建另一個佈局,但它仍然不會工作..即時通訊調用這個從片段如下:

public class ProfileFragment : Fragment 
    { 
     private static Context _context; 
     private static Xamarin.Facebook.Profile _profile; 
     private CircleImageView imgProfile; 
     private TextView userName; 
     private TabLayout tabLayout; 
     private ViewPager viewpager; 
     public override void OnCreate(Bundle savedInstanceState) 
     { 
      base.OnCreate(savedInstanceState); 

      // Create your fragment here 
     } 

     public static Fragment NewInstance(Activity context , Xamarin.Facebook.Profile profile) 
     { 
      _context = context; 
      _profile = profile; 
      Fragment fragment = new ProfileFragment(); 
      return fragment; 
     } 
     public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
     { 

      View view = inflater.Inflate(Resource.Layout.fragmentProfile, container, false); 
      imgProfile = view.FindViewById<CircleImageView>(Resource.Id.imageProfile); 
      tabLayout =view.FindViewById<TabLayout>(Resource.Id.tab_layout); 
      viewpager = view.FindViewById<ViewPager>(Resource.Id.pager); 
      userName = view.FindViewById<TextView>(Resource.Id.user_name); 
      userName.Text = _profile.Name; 
      Picasso.With(_context).Load(_profile.GetProfilePictureUri(180, 180)).Into(imgProfile); 

      FnInitTabLayout(); 

      return view; 
     } 

     void FnInitTabLayout() 
     { 
      tabLayout.SetTabTextColors(Android.Graphics.Color.Aqua, Android.Graphics.Color.AntiqueWhite); 
      //Fragment array 
      var fragments = new Fragment[] 
      { 
       new ActivityFragment(), 
       new SportsFragment(), 
       new AboutFragment() 
      }; 
      //Tab title array 
      var titles = CharSequence.ArrayFromStringArray(new[] { 
       "Feed", 
       "Sports", 
       "About", 
      }); 

      //viewpager holding fragment array and tab title text 
      viewpager.Adapter = new ProileTabsAdapter(FragmentManager, fragments, titles); 
      tabLayout.SetupWithViewPager(viewpager); 
     } 

    } 

當我把它的活動僅在標籤和viewpager他們內部並沒有上述佈局完美的工作,但在這種情況下不是。任何人都可以想到我做錯了什麼?

編輯:

這裏是尋呼機適配器

public class ProileTabsAdapter : FragmentPagerAdapter 
    { 
     private readonly Fragment[] fragments; 

     private readonly ICharSequence[] titles; 

     public ProileTabsAdapter(FragmentManager fm, Fragment[] fragments, ICharSequence[] titles) : base(fm) 
     { 
      this.fragments = fragments; 
      this.titles = titles; 
     } 
     public override int Count 
     { 
      get 
      { 
       return fragments.Length; 
      } 
     } 

     public override Fragment GetItem(int position) 
     { 
      return fragments[position]; 
     } 

     public override ICharSequence GetPageTitleFormatted(int position) 
     { 
      return titles[position]; 
     } 
    } 
+0

您是否實施了ViewPager適配器?分享您的viewpager適配器的代碼 – SripadRaj

+0

我編輯帖子以包含適配器 – Drinv

+0

視圖分頁器的wrap_content在滾動視圖內不起作用。嘗試設置layout_height查看尋呼機 –

回答

0

使用android:fillViewport="true"到您的ScrollView
wrap_content的查看傳呼機不會在Scrollview內工作。