appbar显示在折叠工具栏上方

时间:2017-05-25 00:03:16

标签: android xml android-layout

我正在尝试使用电影标题制作折叠工具栏来代替应用栏。它应该只显示折叠的工具栏而不是应用栏。相反它看起来像 this. 以下是活动的XML布局:

    <android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fl_movie_info"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/info_title"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            android:fitsSystemWindows="true">


            <ImageView
                android:id="@+id/toolbarImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" >
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="24dp">

            <android.support.v7.widget.CardView
                android:id="@+id/cardView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                card_view:cardBackgroundColor="@color/colorCardView">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <ImageView
                        android:id="@+id/iv_info_poster"
                        android:layout_width="150dp"
                        android:layout_height="wrap_content"
                        android:adjustViewBounds="true"
                        android:paddingTop="10dp"
                        android:paddingLeft="10dp"
                        android:paddingBottom="5dp" />

                    <android.support.v7.widget.AppCompatRatingBar
                        android:id="@+id/rb_info_rating"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="?android:attr/ratingBarStyleSmall"
                        android:layout_below="@id/iv_info_poster"
                        android:numStars="5"
                        android:layout_marginLeft="10dp" />
                    <TextView
                        android:id="@+id/tv_info_release_date"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/rb_info_rating"
                        android:paddingBottom="5dp"
                        android:textColor="@android:color/white"
                        android:layout_marginLeft="10dp" />
                    <TextView
                        android:id="@+id/tv_info_synopsis_title"
                        android:text="@string/synopsis"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@id/iv_info_poster"
                        android:paddingLeft="25dp"
                        />
                    <TextView
                        android:id="@+id/tv_info_synopsis"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textColor="@android:color/white"
                        android:layout_toRightOf="@id/iv_info_poster"
                        android:layout_below="@+id/tv_info_synopsis_title"
                        android:paddingLeft="25dp"
                        android:paddingRight="25dp" />

                </RelativeLayout>
            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:id="@+id/cardView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                card_view:cardBackgroundColor="@color/colorCardView">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">


                </RelativeLayout>
            </android.support.v7.widget.CardView>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

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

AndroidManifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bucki_000.popularmoviesapp">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission 
android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MovieInfo"></activity>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:0)

主题可能是问题所在。主题是为AndroidManifest中的活动设置的。

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"     <----- Theme

AppTheme位于res / values中的styles.xml中。尝试通过设置&#34; windowActionBar&#34;来删除默认的ActionBar。和&#34; windowNoTitle&#34;为假。

    style name="YourThemeName" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        ...
        ...