2017-08-29 18 views
0

私は、このレイアウトAndroidビューページが表示されません。

<?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データがありません。次のようにImはフラグメントからこれを呼び出す..私は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彼らの活動の内側と上記レイアウトせずにそれを置くときこのシナリオでは完全には動作しません。誰かが私が間違っていることを考えることができますか?

EDIT:

ここではViewPagerがwidth="wrap_content"またはheight="wrap_content" attrsにはサポートしていませんページャアダプタ

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用アダプタを実装しましたか?あなたのビューページアダプターのコードを共有 – SripadRaj

+0

アダプターを含めるために投稿を編集しました – Drinv

+0

wrap_content of view pagerはscrollview内では機能しません。ビューページャーのlayout_heightを設定しようとしてください –

答えて

0

使用android:fillViewport="true"あなたScrollViewに(ViewPagerontent Cラップ W)。
wrap_contentのビューページャは、Scrollviewの内部では機能しません。

関連する問題