当其他视图小于一个屏幕时,BottomNavigationView会向上移动

时间:2019-06-11 09:55:17

标签: android xml scrollview bottomnavigationview

我在ConstraintLayout中有一个imageView,ProgressBar,TextView和RecyclerView,我想使其可滚动,但是我不希望BottomNavigationView移动。当内容小于一个屏幕时,我不确定如何使其保持向下状态。我尝试了此处提出的类似解决方案,例如NestedScrollView,但它们只是使某些视图消失了。

我不知道我的代码是否粘贴正确,所以这里是Github链接:https://github.com/PiotrDawidziuk/QuizO2Api/blob/master/app/src/main/res/layout/activity_take_quiz.xml

我的代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context=".activities.DetailActivity">
<android.support.constraint.ConstraintLayout     
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:context=".activities.TakeQuizActivity">

<ProgressBar
    android:id="@+id/simpleProgressBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    />

<TextView
    android:id="@+id/message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/activity_horizontal_margin"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    android:text="@string/title_home"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@id/simpleProgressBar"
    />

<ImageView
    android:id="@+id/take_quiz_question_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@+id/message"
    app:layout_constraintStart_toStartOf="parent"
    />

<android.support.v7.widget.RecyclerView
    android:id="@+id/take_quiz_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@+id/take_quiz_question_image"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toTopOf="@id/nav_view"
    app:layout_constraintEnd_toEndOf="parent"
    >
</android.support.v7.widget.RecyclerView>


<android.support.design.widget.BottomNavigationView
    android:id="@+id/nav_view"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:background="?android:attr/windowBackground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/bottom_nav_menu"/>
 </android.support.constraint.ConstraintLayout>
</ScrollView>

我稍微更改了代码,将ScrollView放在ConstraintLayout内,然后将LinearLayout放在其他所有内容上。它滚动了一点,但由于某些原因却切掉了RecyclerView的底部:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
tools:context=".activities.DetailActivity">
<ScrollView
    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="0dp"
    tools:context=".activities.TakeQuizActivity"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    <ProgressBar
        android:id="@+id/simpleProgressBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        />

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/activity_horizontal_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:text="@string/title_home"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/simpleProgressBar"
        />

    <ImageView
        android:id="@+id/take_quiz_question_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/message"
        app:layout_constraintStart_toStartOf="parent"
        />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/take_quiz_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/take_quiz_question_image"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintEnd_toEndOf="parent"
        >
    </android.support.v7.widget.RecyclerView>
    </LinearLayout>
</ScrollView>
<android.support.design.widget.BottomNavigationView
    android:id="@+id/nav_view"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:background="?android:attr/windowBackground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/bottom_nav_menu"/>
</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

您应该将#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } 移到scrollView内。但是,在您的代码中,情况恰恰相反。看看

constaraintLayout