可折叠工具栏展开状态出现问题

时间:2018-09-26 07:27:57

标签: xamarin.android android-coordinatorlayout android-collapsingtoolbarlayout

我有一个片段,其中包含一个viewpager和一个可折叠工具栏,它们在可折叠工具栏中具有图像。片段HasOptionsProperty设置为true,它具有多个菜单项以及后向导航箭头。问题是可折叠工具栏中的内容无法正确显示。工具栏内的图像向上移动,因此与支撑操作栏重叠。而且,在滚动查看页面时,选项卡布局会与工具栏重叠。我希望标签栏保持在工具栏的正下方,以便折叠后标题应该可见。

预期的行为:展开时,可折叠内容应位于工具栏下方,而折叠后的布局应位于工具栏附近。

当前条件: enter image description here

代码: MainActivity:

[Activity(MainLauncher = true, Icon = "@mipmap/icon", Theme ="@style/MyTheme")]
    public class MainActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
            SupportFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, new BaseFragment()).Commit();
        }
    }

BaseFragment

public class BaseFragment : Fragment, ViewPager.IOnPageChangeListener
    {
        private ImageView _coverArt, banner;
        private FragmentOne one;
        private FragmentTwo two;

        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            HasOptionsMenu = true;
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            return inflater.Inflate(Resource.Layout.Base, container, false);
        }

        public override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            Android.Support.V7.Widget.Toolbar toolbar = (Android.Support.V7.Widget.Toolbar)view.FindViewById(Resource.Id.htab_toolbar);
            ((AppCompatActivity)Activity).SetSupportActionBar(toolbar);
            ((AppCompatActivity)Activity).SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            ((AppCompatActivity)Activity).SupportActionBar.SetDisplayShowTitleEnabled(true);
            ((AppCompatActivity)Activity).Title = "My Title";
            TabLayout mTabLayout = (TabLayout)view.FindViewById(Resource.Id.htab_tabs);
            _coverArt = (ImageView)view.FindViewById(Resource.Id.imageView);
            banner = view.FindViewById<ImageView>(Resource.Id.banner);
            ViewPager mViewPager = (ViewPager)view.FindViewById(Resource.Id.htab_viewpager);

            one = new FragmentOne();
            two = new FragmentTwo();
            DetailsPagerAdapter mViewPagerAdapter = new DetailsPagerAdapter(ChildFragmentManager);
            mViewPagerAdapter.AddFragment(one, "OverView");
            mViewPagerAdapter.AddFragment(two, "Result");
            mTabLayout.SetupWithViewPager(mViewPager);
            mViewPager.AddOnPageChangeListener(this);
            mViewPager.Adapter = mViewPagerAdapter;
        }

        public void OnPageScrollStateChanged(int state)
        {

        }

        public void OnPageScrolled(int position, float positionOffset, int positionOffsetPixels)
        {

        }

        public void OnPageSelected(int position)
        {
            switch (position)
            {
                case 0:
                    break;
                case 1:
                    break;
            }

        }

        public override void OnCreateOptionsMenu(IMenu menu, MenuInflater inflater)
        {
            inflater.Inflate(Resource.Menu.menu, menu);
        }
    }

BaseFragment布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/htab_maincontent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/htab_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">
        <android.support.design.widget.CollapsingToolbarLayout
            app:titleEnabled="false"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp">
            <RelativeLayout
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:layout_width="170dp"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginBottom="40dp"
                android:layout_gravity="center"
                android:background="@android:color/holo_green_dark"
                android:id="@+id/relative1">
                <ImageView
                    android:id="@+id/imageView"
                    android:transitionName="sample_string"
                    android:layout_width="170dp"
                    android:layout_height="270dp"
                    android:scaleType="fitCenter"
                    android:paddingBottom="28dp"
                    android:layout_centerInParent="true"
                    android:layout_marginBottom="15dp"
                    android:src="@drawable/app_art"
                    android:adjustViewBounds="true"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.75" />
                <ImageView
                    android:id="@+id/banner"
                    android:layout_alignBottom="@id/imageView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="28dp"
                    android:paddingRight="4dp"
                    android:visibility="invisible"
                    android:src="@drawable/blue_bg"
                    android:layout_alignRight="@id/imageView" />
            </RelativeLayout>
            <android.support.v7.widget.Toolbar
                android:id="@+id/htab_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_scrollFlags="scroll|enterAlways"
                app:layout_collapseMode="pin" />
        </android.support.design.widget.CollapsingToolbarLayout>
        <android.support.design.widget.TabLayout
                android:id="@+id/htab_tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabSelectedTextColor="#dc3545"
                app:tabIndicatorColor="#dc3545"
                android:layout_gravity="bottom" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/htab_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_collapseMode="parallax"
        app:tabSelectedTextColor="#dc3545" />
</android.support.design.widget.CoordinatorLayout>

0 个答案:

没有答案