J'ai cette mise en pageAndroid viewpager ne s'affiche pas?
<?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>
La dernière LinearLayout montre les onglets, mais quand je les changer, il n'y a pas de données viewpager que ce soit. J'ai essayé de créer une autre disposition pour la tablayout, mais il ne sera pas encore du travail .. Im appeler ceci d'un fragment comme suit:
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);
}
}
Quand je l'ai mis dans une activité et sans la mise en page ci-dessus que l'onglet et la viewpager ils fonctionne parfaitement mais dans ce scénario pas. Quelqu'un peut-il penser à ce que je fais mal?
EDIT:
Voici l'adaptateur pager
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];
}
}
Avez-vous implémenté un adaptateur pour ViewPager? Partagez le code de votre adaptateur viewpager – SripadRaj
J'ai modifié le post pour inclure l'adaptateur – Drinv
wrap_content de vue pager ne fonctionnera pas à l'intérieur de scrollview. essayer de mettre layout_height pour voir pager –