如何将内容保持在工具栏下方?

时间:2018-11-19 23:12:03

标签: android

我需要我的工具栏在向上滑动时消失。我的recyclerview可以正常运行,但是内容首先显示在工具栏后面,直到我向上滚动。如何将我的内容保持在工具栏下方,以便在向上滑动之前将其全部显示?请检查下面的代码,如果您能指出我做错了什么,请告诉我。有很多SO职位稍微解决了这个问题,但是几个小时后,我决定问一下。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerViewId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp" />

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Light">

    <android.support.v7.widget.Toolbar

        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

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

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

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

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 
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="wrap_content"
app:cardBackgroundColor="#37474F"
app:cardElevation="0dp"
app:cardMaxElevation="0dp"
app:cardUseCompatPadding="true"
android:id="@+id/content_layout">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/main.appbar">

        <ImageView
            android:id="@+id/coin_icon"
            android:layout_width="56dp"
            android:layout_height="56dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@mipmap/ic_launcher" />

        <TextView
            android:id="@+id/coin_symbol"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginBottom="8dp"
            android:text="@string/BTC"
            android:textColor="#E8EAF6"
            android:textStyle="bold"
            app:layout_constraintStart_toEndOf="@id/coin_icon"
            app:layout_constraintTop_toTopOf="@+id/coin_icon" />

        <TextView
            android:id="@+id/coin_divider"
            android:layout_width="3dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="4dp"
            android:text="@string/divider"
            android:textColor="#E8EAF6"
            android:textStyle="bold"
            app:layout_constraintStart_toEndOf="@id/coin_symbol"
            app:layout_constraintTop_toTopOf="@+id/coin_icon" />

        <TextView
            android:id="@+id/coin_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginBottom="8dp"
            android:text="@string/Bitcoin"
            android:textColor="#E8EAF6"
            app:layout_constraintStart_toEndOf="@id/coin_divider"
            app:layout_constraintTop_toTopOf="@+id/coin_icon" />

        <TextView
            android:id="@+id/coin_sign"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="4dp"
            android:layout_marginLeft="8dp"
            android:layout_marginBottom="8dp"
            android:text="@string/money_sign"
            android:textColor="#E8EAF6"
            android:textStyle="bold"
            app:layout_constraintEnd_toStartOf="@id/priceUsdText"
            app:layout_constraintTop_toTopOf="@+id/coin_icon" />

        <TextView
            android:id="@+id/priceUsdText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginBottom="8dp"
            android:text="@string/USD"
            android:textColor="#E8EAF6"
            android:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="@+id/coin_icon" />

        <TextView
            android:id="@+id/oneHourText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="20dp"
            android:text="@string/one_hour"
            android:textColor="#E8EAF6"
            app:layout_constraintStart_toEndOf="@id/coin_icon"
            app:layout_constraintTop_toBottomOf="@+id/coin_symbol" />

        <TextView
            android:id="@+id/percentChange1hrText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="12dp"
            android:layout_marginTop="20dp"
            android:textColor="@color/colorPrimary"
            app:layout_constraintStart_toEndOf="@id/oneHourText"
            app:layout_constraintTop_toBottomOf="@+id/coin_divider" />

        <TextView
            android:id="@+id/twentyFourHourText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="56dp"
            android:layout_marginEnd="8dp"
            android:text="@string/twenty_four_hr"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toEndOf="@+id/coin_icon"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/percentChange24hrText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textColor="@color/colorPrimary"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/coin_icon"
            tools:layout_editor_absoluteX="157dp"
            tools:layout_editor_absoluteY="72dp" />

        <TextView
            android:id="@+id/sevenDayText"
            android:name="@string/seven_day"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="56dp"
            android:layout_marginEnd="12dp"
            app:layout_constraintEnd_toStartOf="@id/percentChange7dText"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/percentChange7dText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:textColor="@color/colorPrimary"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/coin_icon" />

    </android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>

0 个答案:

没有答案