java - 底部导航栏被 ScrollView 布局推出 View 之外

标签 java android android-layout

开门见山。我想为我的应用程序有一个底部导航栏,然后在顶部有一个工具栏,中间是一个 ScrollView ,其中将放置内容。

现在的问题是 ScrollView 布局将导航栏推出 View ,现在导航栏不会显示。

As you can see, the navigation bar isn't showing because the ScrollView takes up the bottom of the screen too.

我尝试过的另一个解决方案,但结果导航栏弹出在 ScrollView 顶部

That blue bar below the Home toolbar is the navigation bar.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="polytechnic.temasek.bluebeatsmusicapplication.HomePageActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:background="@drawable/bluebeatsbackground2">

    <TextView
        android:id="@+id/toolbartitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Home"
        android:textColor="@android:color/white"
        android:textSize="32sp"
        android:textStyle="bold" />
</android.support.v7.widget.Toolbar>


<ScrollView
        android:layout_width="match_parent"
        android:layout_height="539dp"
    >

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="0dp">

            [Content inside] 
            </android.support.constraint.ConstraintLayout>

    </ScrollView>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/the_bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="bottom"
    android:background="@color/colorPrimary"
    app:itemBackground="@color/colorPrimary">
    </android.support.design.widget.BottomNavigationView>
</LinearLayout>

到目前为止,我只能将 Scrollview 的高度强制到某个 dp 来为导航栏腾出空间,但肯定还有另一种我认为缺少的方法?

最佳答案

您最好使用相对布局约束布局(我建议使用约束布局)来处理这种情况。

我已将您的布局修改为约束布局。 我已经将滚动条的 marginBottom 值欺骗为bottomNavigationBar的高度[否则,scrollView的一些内容保留在bottomNavBar后面]。

enter image description here

<android.support.constraint.ConstraintLayout 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">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#000"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/toolbartitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Home"
            android:textColor="@android:color/white"
            android:textSize="32sp"
            android:textStyle="bold" />

    </android.support.v7.widget.Toolbar>

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="50dp"
        android:layout_marginTop="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent">

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="@string/long_text"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </android.support.constraint.ConstraintLayout>
    </ScrollView>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/the_bottom_navigation"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimary"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent">

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


</android.support.constraint.ConstraintLayout>

关于java - 底部导航栏被 ScrollView 布局推出 View 之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45126897/

相关文章:

java - 如何使用ant在命令行中输入项目名称?

JavaFx:获取点击的按钮值

android - 从工作区删除项目

使用 OpenCV 或其他库更改 Android 相机背景

android - 如何删除 gridview 单元格中的额外空间 - Android

安卓多屏设计

JavaFX 程序在运行时锁定/卡住

android - 如何在图像缩放android中捏缩放图像?

java - 应用程序启动时图像超出 imageview

java - Spring 4.0 : Resolve Type of GenericDao