Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 滚动时如何使工具栏保持在顶部?(安卓工作室)_Xml_Android Studio_Scroll_Toolbar - Fatal编程技术网

Xml 滚动时如何使工具栏保持在顶部?(安卓工作室)

Xml 滚动时如何使工具栏保持在顶部?(安卓工作室),xml,android-studio,scroll,toolbar,Xml,Android Studio,Scroll,Toolbar,我创建了一个适用于导航的工具栏。问题是当我滚动工具栏时并没有固定在顶部。我滚动离开它。当然,我想让它一直保持在顶端。我认为问题在于我在滚动视图层次结构中有工具栏xml。看起来是这样的: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/

我创建了一个适用于导航的
工具栏
。问题是当我滚动
工具栏时
并没有固定在顶部。我滚动离开它。当然,我想让它一直保持在顶端。我认为问题在于我在
滚动视图
层次结构中有
工具栏
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"
android:fillViewport="true"
tools:context="com.nollvision.slothmode.nollvision.DetailActivity2">

<android.support.constraint.ConstraintLayout
    android:id="@+id/detail2_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:backgroundTint="@color/colorPrimaryDark"
        android:minHeight="?attr/actionBarSize"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <ImageView... AND SO ON....

滚动视图->约束->子对象。像这样:

<?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="com.nollvision.slothmode.nollvision.DetailActivity2">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:backgroundTint="@color/colorPrimaryDark"
    android:minHeight="?attr/actionBarSize"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

<android.support.constraint.ConstraintLayout
        android:id="@+id/detail2_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

<ImageView...AN SO ON


您应该为此使用框架布局

类似这样的:

 <?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="com.nollvision.slothmode.nollvision.DetailActivity2">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:backgroundTint="@color/colorPrimaryDark"
        android:minHeight="?attr/actionBarSize"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
            android:id="@+id/detail2_background"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

真棒的人,真是魅力四射!非常感谢您抽出时间来帮助我@Rohithhammaiah!当然,对布局进行了一些修改,但工具栏现在仍然位于顶部。但要指出的一点是,对于那些有相同问题的人来说,如果导航栏不显示,则为其设置
android:elevation=“5dp”
。再一次,非常感谢!:)