如何将带有片段的viewPager放入另一个带有片段的viewPager内?

时间:2019-02-13 18:06:57

标签: c# android xamarin.android

我试图将viewPager放置在应用程序的主页选项卡中,以便用户可以滚动浏览图片/视频,同时能够切换父viewPager中的选项卡。我禁用了父选项卡的滑动。目前,首页位于所有其他选项卡的后面,当我进入首页时,子viewPager中的图片不会只显示测试视频,而是可以在空白处滑动。

MainActivity.cs

 protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.activity_main);

        BottomNavigationView navigation = 
        FindViewById<BottomNavigationView>(Resource.Id.navigation);
        navigation.SetOnNavigationItemSelectedListener(this);

        //FragManager
        fm = this.SupportFragmentManager;

        //Page Change Adapter Setup
        MPA = new MasterPagerAdapter(fm, GetFragmentsMP());

        viewPagerNav = FindViewById<CustomViewPager>(Resource.Id.PageNav);
        viewPagerNav.disableScroll(true);
        viewPagerNav.Adapter = MPA;

        //Adapter
        Adapter = new MyPagerAdapter(fm, GetFragments());

        FrameLayout container = FindViewById<FrameLayout> 
        (Resource.Id.Frame);

        View view = View.Inflate(this, Resource.Layout.MainPage, 
        container);

        viewPager = view.FindViewById<ViewPager>(Resource.Id.UserPicture);
        viewPager.Adapter = Adapter;

    }

MainActivity.axml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:actionBarNavMode="tabs"
tools:menu="navigation">

<FameAndroid.CustomViewPager
    android:id="@+id/PageNav"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:layout_below="@+id/toolbar"
    xmlns:android="http://schemas.android.com/apk/res/android"
android:translationZ="1dp"/>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="@android:color/transparent"
    android:layout_alignParentBottom="true"
    app:menu="@menu/navigation"
    android:minWidth="25px"
    android:minHeight="25px">
</android.support.design.widget.BottomNavigationView>

<Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/actionBarSize"
    android:background="?android:attr/colorPrimary"
android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar"
    android:translationZ="3dp">

<ImageButton
        android:id="@+id/refreshButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:background="@android:color/transparent"
        android:layout_below="@+id/toolbar"/>

<ImageButton
        android:id="@+id/reportButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:background="@android:color/transparent"
        android:layout_below="@+id/toolbar"
        android:layout_gravity="right"/>
</Toolbar >

<ImageView
    android:id="@+id/logo"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="center"
    android:src="@drawable/ic_launcher"
    android:translationZ="4dp"/>

MainPage.axml(父页面片段之一)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:id="@+id/containerMainPage"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.view.ViewPager
    android:id="@+id/UserPicture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:layout_below="@+id/toolbar"
    xmlns:android="http://schemas.android.com/apk/res/android"/>

  <ImageButton
android:id="@+id/likeButton"    
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher"
android:background="@android:color/transparent"
android:layout_marginBottom="150dp"
    android:layout_marginLeft="60dp"
android:layout_alignParentBottom = "true"
   />

<ImageButton
android:id="@+id/followButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:background="@android:color/transparent"
android:layout_marginBottom="150dp"
android:layout_marginRight="60dp"
android:layout_alignParentBottom = "true"
android:layout_alignParentRight="true" 
    />

</RelativeLayout> 

0 个答案:

没有答案