与底部导航栏一起使用时,底部向上滑动不起作用

时间:2018-01-20 11:17:11

标签: android material-design

在我的应用程序中,我使用底部工作表和底部导航栏,其中底部工作表向上滑动(扩展)操作无效,因此需要一些建议才能再次滑动工作。

注意:扩展底部工作表会在按钮单击时以编程方式工作,但它不会在滑动时展开。

这里更新是我的布局 `

<?xml version="1.0" encoding="utf-8"?><!--suppress XmlUnusedNamespaceDeclaration -->
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".TabActivity">

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom"
            android:animateLayoutChanges="true"
            android:animationCache="true"
            android:background="@android:color/white"
            android:clickable="true"
            android:focusable="true"
            android:hapticFeedbackEnabled="true"
            android:isScrollContainer="true"
            android:overScrollMode="always"
            app:menu="@menu/bottom_nav" />

        <LinearLayout
            android:id="@+id/bottom_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center|bottom"
            android:background="@android:color/transparent"
            android:orientation="vertical"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            app:behavior_hideable="false"
            app:behavior_peekHeight="20dp"
            app:elevation="10dp"
            app:layout_behavior="@string/bottom_sheet_behavior">


            <ImageButton
                android:id="@+id/up"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                map:srcCompat="@drawable/ic_up"
                android:contentDescription="@string/upwards" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:clickable="true"
                android:focusable="true"
                app:tabMode="scrollable">

                <android.support.design.widget.TabItem
                    android:id="@+id/tab1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/temples" />

                <android.support.design.widget.TabItem
                    android:id="@+id/tab2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/mosques" />

                <android.support.design.widget.TabItem
                    android:id="@+id/tab3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/church" />

                <android.support.design.widget.TabItem
                    android:id="@+id/tab5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/historic_places" />

            </android.support.design.widget.TabLayout>

            <android.support.v4.view.ViewPager
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:background="#e6ffffff"
                android:clickable="true"
                android:fadeScrollbars="true"
                android:fadingEdge="horizontal|vertical"
                android:focusable="true"
                android:isScrollContainer="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        </LinearLayout>

    </android.support.design.widget.CoordinatorLayout>

</android.support.design.widget.CoordinatorLayout>

`

这是java代码 `

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    //initializing bottom sheet
            View bottomSheet = findViewById(R.id.bottom_layout);
            behavior = BottomSheetBehavior.from(bottomSheet);

            // Set up the ViewPager with the sections adapter.
            ViewPager mViewPager = findViewById(R.id.container);
            mViewPager.setAdapter(mSectionsPagerAdapter);
            /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                mViewPager.setContextClickable(true);
                TabLayout tabLayout = findViewById(R.id.tabs);
                tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
            }*/

            //giving bottom sheet a button and also onclick listener
            upSlider = findViewById(R.id.up);
            upSlider.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (behavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
                        upSlider.setImageDrawable(getResources().getDrawable(R.drawable.ic_up));
                        behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                    } else {
                        upSlider.setImageDrawable(getResources().getDrawable(R.drawable.ic_down));
                        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                    }
                }
            });

            //bottom sheet behavior
            behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
                @Override
                public void onStateChanged(@NonNull View bottomSheet, int newState) {
                    switch (newState) {
                        case BottomSheetBehavior.STATE_DRAGGING:
                            Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_DRAGGING");
                            break;
                        case BottomSheetBehavior.STATE_SETTLING:
                            Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_SETTLING");
                            break;
                        case BottomSheetBehavior.STATE_EXPANDED:
                            upSlider.setImageDrawable(getResources().getDrawable(R.drawable.ic_down));
                            Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_EXPANDED");
                            break;
                        case BottomSheetBehavior.STATE_COLLAPSED:
                            upSlider.setImageDrawable(getResources().getDrawable(R.drawable.ic_up));
                            Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_COLLAPSED");
                            break;
                        case BottomSheetBehavior.STATE_HIDDEN:
                            Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_HIDDEN");
                            break;
                    }
                }

                @Override
                public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                    Log.i("BottomSheetCallback", "slideOffset:  " + slideOffset);
                }
            });

            //initialising bottom Navigation bar
            BottomNavigationView bottomNavigationView = findViewById(R.id.navigation);

            bottomNavigationView.setOnNavigationItemSelectedListener
                    (new BottomNavigationView.OnNavigationItemSelectedListener() {
                        @Override
                        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                            new placingMarkers().execute(item.getItemId());
                            return true;
                        }
                    });
}

`

只有向上滑动的手势无法正常工作。

0 个答案:

没有答案