BottomNavigation下的ViewPager

问题描述 投票:0回答:1

我在viewpager中有列表,我在底部有音频播放器。但是我的viewpager并没有结束音频播放器的启动。我在viewpager中看不到我的最后2-3个项目。而且我不想使用MarginBottom

一些截图enter image description here

enter image description here

我的activity.xml

<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/coordinatorLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- AppBar Layout   -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="fill_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        <!-- Tab Layout for creating tabs -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.AppBarLayout>
    <!-- Helps handing the Fragments for each Tab -->



    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.BottomNavigationView
        android:layout_width="fill_parent"
        android:layout_height="90dp"
        android:layout_marginTop="5dp"
        android:layout_below="@+id/viewPager"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:layout_gravity="bottom"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

    <android.support.design.widget.NavigationView

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:paddingLeft="10dp"
            android:layout_gravity="center"
            android:paddingRight="10dp"
            android:orientation="horizontal">

            <ImageButton
                android:id="@+id/btnBackward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="50dp"
                android:layout_marginBottom="4dp"
                android:src="@android:drawable/ic_media_rew" />

            <ImageButton
                android:id="@+id/btnPlay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/btnBackward"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@+id/btnBackward"
                android:src="@android:drawable/ic_media_play" />

            <ImageButton
                android:id="@+id/btnPause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/btnPlay"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@+id/btnPlay"
                android:src="@android:drawable/ic_media_pause" />

            <ImageButton
                android:id="@+id/btnForward"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/btnPause"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@+id/btnPause"
                android:contentDescription="@+id/imageButton3"
                android:src="@android:drawable/ic_media_ff" />

            <TextView
                android:id="@+id/txtStartTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/sBar"
                android:text="0 min, 0 sec" />

            <SeekBar
                android:id="@+id/sBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/btnBackward"
                android:layout_toLeftOf="@+id/txtSongTime"
                android:layout_toRightOf="@+id/txtStartTime" />

            <TextView
                android:id="@+id/txtSongTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/sBar"
                android:layout_toRightOf="@+id/btnForward"
                android:text="0 min, 0 sec " />
        </RelativeLayout>


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

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

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

我尝试了几种解决方案,但没有一个起作用。我能找到的唯一解决方案是使用marginbottom,但我认为那将是错误的选择。

任何帮助都会很棒。谢谢。

java android android-layout navigation android-viewpager
1个回答
0
投票

您可以通过将ViewPagerBottomNavigationView包裹在ConstraintLayout内并添加约束,使ViewPager的底部应位于BottomNavigationView的顶部来解决此问题,使用以下方法:[ app:layout_constraintBottom_toTopOf

中的ViewPager属性
    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        ...
        app:layout_constraintBottom_toTopOf="@id/bottom_nav_view"

然后使ViewPager的高度匹配约束,而不是fill_parentmatch_parent

将此更改应用于您的布局:

<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/coordinatorLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- AppBar Layout   -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="fill_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        <!-- Tab Layout for creating tabs -->
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.AppBarLayout>
    <!-- Helps handing the Fragments for each Tab -->


    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:layout_constraintBottom_toTopOf="@id/bottom_nav_view"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottom_nav_view"
            android:layout_width="match_parent"
            android:layout_height="90dp"
            android:layout_marginTop="5dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_constraintBottom_toBottomOf="parent"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <android.support.design.widget.NavigationView

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_gravity="center"
                    android:orientation="horizontal"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp">

                    <ImageButton
                        android:id="@+id/btnBackward"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_marginLeft="50dp"
                        android:layout_marginBottom="4dp"
                        android:src="@android:drawable/ic_media_rew" />

                    <ImageButton
                        android:id="@+id/btnPlay"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignTop="@+id/btnBackward"
                        android:layout_marginLeft="20dp"
                        android:layout_toRightOf="@+id/btnBackward"
                        android:src="@android:drawable/ic_media_play" />

                    <ImageButton
                        android:id="@+id/btnPause"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignTop="@+id/btnPlay"
                        android:layout_marginLeft="20dp"
                        android:layout_toRightOf="@+id/btnPlay"
                        android:src="@android:drawable/ic_media_pause" />

                    <ImageButton
                        android:id="@+id/btnForward"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignTop="@+id/btnPause"
                        android:layout_marginLeft="20dp"
                        android:layout_toRightOf="@+id/btnPause"
                        android:contentDescription="@+id/imageButton3"
                        android:src="@android:drawable/ic_media_ff" />

                    <TextView
                        android:id="@+id/txtStartTime"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignTop="@+id/sBar"
                        android:text="0 min, 0 sec" />

                    <SeekBar
                        android:id="@+id/sBar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_above="@+id/btnBackward"
                        android:layout_toLeftOf="@+id/txtSongTime"
                        android:layout_toRightOf="@+id/txtStartTime" />

                    <TextView
                        android:id="@+id/txtSongTime"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignTop="@+id/sBar"
                        android:layout_toRightOf="@+id/btnForward"
                        android:text="0 min, 0 sec " />
                </RelativeLayout>


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

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

    </android.support.constraint.ConstraintLayout>


</android.support.design.widget.CoordinatorLayout>
© www.soinside.com 2019 - 2024. All rights reserved.