Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.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
Android 是否添加固定的选项卡栏,并将其固定到顶部,同时显示滚动内容?_Android_Xml_Android Activity_Tabs - Fatal编程技术网

Android 是否添加固定的选项卡栏,并将其固定到顶部,同时显示滚动内容?

Android 是否添加固定的选项卡栏,并将其固定到顶部,同时显示滚动内容?,android,xml,android-activity,tabs,Android,Xml,Android Activity,Tabs,我试着回答,但我无法达到与我当前主要活动相同的外观和行为 我应该对现有的主要活动进行哪些更改,以添加固定的选项卡栏,该选项卡栏固定在顶部,并带有滚动内容,如下图所示 下面是我当前主要活动的.GIF:i.stack.imgur.com/Yj0cv.GIF 这里有一个链接指向名为android的完整项目: 下面是styles.xml: 谷歌有设计支持库,你可以用它实现折叠工具栏,你不需要任何第三方库 除了固定视图外,您还可以使用app:layout\u collapseMode=parallax和可

我试着回答,但我无法达到与我当前主要活动相同的外观和行为

我应该对现有的主要活动进行哪些更改,以添加固定的选项卡栏,该选项卡栏固定在顶部,并带有滚动内容,如下图所示

下面是我当前主要活动的.GIF:i.stack.imgur.com/Yj0cv.GIF

这里有一个链接指向名为android的完整项目:

下面是styles.xml:


谷歌有设计支持库,你可以用它实现折叠工具栏,你不需要任何第三方库

除了固定视图外,您还可以使用app:layout\u collapseMode=parallax和可选的app:layout\u collapseparlaxmultiplier=0.7设置视差倍增器,以实现视差滚动,例如折叠工具栏布局中的同级图像视图

作为示例,您可以使用以下内容:

<android.support.design.widget.AppBarLayout
    android:layout_height="186dp"
    android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
    <android.support.v7.widget.Toolbar
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:layout_collapseMode="pin"/>
    </android.support.design.widget.CollapsingToolbarLayout>
您可以对状态栏下方要绘制的任何项目使用fitsSystemWindows

然后需要添加AppBarLayout:

然后在里面,你可以添加如下内容:

<android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        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">

        <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.design.widget.CollapsingToolbarLayout>

谷歌有设计支持库,你可以用它实现折叠工具栏,你不需要任何第三方库

除了固定视图外,您还可以使用app:layout\u collapseMode=parallax和可选的app:layout\u collapseparlaxmultiplier=0.7设置视差倍增器,以实现视差滚动,例如折叠工具栏布局中的同级图像视图

作为示例,您可以使用以下内容:

<android.support.design.widget.AppBarLayout
    android:layout_height="186dp"
    android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
    <android.support.v7.widget.Toolbar
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:layout_collapseMode="pin"/>
    </android.support.design.widget.CollapsingToolbarLayout>
您可以对状态栏下方要绘制的任何项目使用fitsSystemWindows

然后需要添加AppBarLayout:

然后在里面,你可以添加如下内容:

<android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        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">

        <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.design.widget.CollapsingToolbarLayout>

只是创造了你想要的行为。不应该这么复杂。这里是所有视图的主要XML。但我也已经创建了这个样本项目,请写在这里,如果我需要分享完整的项目

屏风

主XML

以你为例

我在这里分享另一个例子,它应该适合您的代码。我为您的示例附上了所有视图ID。检查一下

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_below="@+id/toolbar"
            android:layout_centerHorizontal="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id"
            app:layout_collapseMode="pin"></com.google.android.gms.ads.AdView>


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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/messageRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom |center_horizontal"
            android:layout_marginBottom="100dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/addMessageImageView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@android:drawable/ic_dialog_alert" />

            <EditText
                android:id="@+id/messageEditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1" />

            <Button
                android:id="@+id/sendButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:enabled="false"
                android:text="SEND" />

        </LinearLayout>

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="100dp"
            android:layout_centerVertical="true" />

    </FrameLayout>


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

只是创造了你想要的行为。不应该这么复杂。这里是所有视图的主要XML。但我也已经创建了这个样本项目,请写在这里,如果我需要分享完整的项目

屏风

主XML

以你为例

我在这里分享另一个例子,它应该适合您的代码。我为您的示例附上了所有视图ID。检查一下

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_below="@+id/toolbar"
            android:layout_centerHorizontal="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id"
            app:layout_collapseMode="pin"></com.google.android.gms.ads.AdView>


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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/messageRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom |center_horizontal"
            android:layout_marginBottom="100dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/addMessageImageView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@android:drawable/ic_dialog_alert" />

            <EditText
                android:id="@+id/messageEditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1" />

            <Button
                android:id="@+id/sendButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:enabled="false"
                android:text="SEND" />

        </LinearLayout>

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="100dp"
            android:layout_centerVertical="true" />

    </FrameLayout>


</android.support.design.widget.CoordinatorLayout>
将固定视图放在RelativeLayout中,并将滚动内容移动到CoordinatorLayout中。像这样:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    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:layoutDirection="ltr"
    tools:context=".MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/linearLayout">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/AppTheme.PopupOverlay"
                app:tabMode="fixed" />

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

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

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

                <com.google.android.gms.ads.AdView
                    android:id="@+id/adView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_alignParentTop="true"
                    ads:adSize="BANNER"
                    ads:adUnitId="@string/banner_ad_unit_id">
                </com.google.android.gms.ads.AdView>

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/messageRecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:nestedScrollingEnabled="false"
                    android:layout_below="@+id/adView" />
            </RelativeLayout>
        </android.support.v4.widget.NestedScrollView>

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

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/addMessageImageView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_add_black_24dp" />

        <EditText
            android:id="@+id/messageEditText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1" />

        <Button
            android:id="@+id/sendButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:enabled="false"
            android:text="SEND" />
    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />
</RelativeLayout>
将固定视图放在RelativeLayout中,并将滚动内容移动到CoordinatorLayout中。像这样:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    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:layoutDirection="ltr"
    tools:context=".MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/linearLayout">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/AppTheme.PopupOverlay"
                app:tabMode="fixed" />

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

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

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

                <com.google.android.gms.ads.AdView
                    android:id="@+id/adView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_alignParentTop="true"
                    ads:adSize="BANNER"
                    ads:adUnitId="@string/banner_ad_unit_id">
                </com.google.android.gms.ads.AdView>

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/messageRecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:nestedScrollingEnabled="false"
                    android:layout_below="@+id/adView" />
            </RelativeLayout>
        </android.support.v4.widget.NestedScrollView>

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

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/addMessageImageView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_add_black_24dp" />

        <EditText
            android:id="@+id/messageEditText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1" />

        <Button
            android:id="@+id/sendButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:enabled="false"
            android:text="SEND" />
    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />
</RelativeLayout>
试试上面的代码

Style.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:colorButtonNormal">@drawable/button_selector</item>
    <item name="colorButtonNormal">@drawable/button_selector</item>
    <item name="android:buttonStyle">@style/FriendlyButtonStyle</item>
</style>

<style name="FriendlyButtonStyle" parent="Widget.AppCompat.Button">
    <item name="android:textColor">@color/colorTitle</item>

</style>
在这里,如果您不想将属性更改为“NoActionBar”,那么也可以像上面那样在AndroidManifest.xml文件中设置它

<activity android:name=".MainActivity"
        android:theme="@style/Theme.AppCompat.NoActionBar"/>
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="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.google.firebase.codelab.friendlychat.MainActivity"
    android:id="@+id/coordinatorLayout">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabGravity="center"
            app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextColor="@android:color/white"
            app:tabIndicatorHeight="2dp"
            app:tabIndicatorColor="@android:color/white"/>

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


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.google.firebase.codelab.friendlychat.MainActivity">

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            app:adSize="BANNER"
            app:adUnitId="@string/banner_ad_unit_id">
        </com.google.android.gms.ads.AdView>

        <include
            layout="@layout/maincontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/adView"/>


        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:orientation="horizontal"
            android:layout_marginBottom="50dp">

            <ImageView
                android:id="@+id/addMessageImageView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@drawable/ic_add_black_24dp"/>

            <EditText
                android:id="@+id/messageEditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"/>

            <Button
                android:id="@+id/sendButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:enabled="false"
                android:text="SEND"/>

        </LinearLayout>

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"/>
    </RelativeLayout>

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

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/messageRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       />

</LinearLayout>
试试上面的代码

Style.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:colorButtonNormal">@drawable/button_selector</item>
    <item name="colorButtonNormal">@drawable/button_selector</item>
    <item name="android:buttonStyle">@style/FriendlyButtonStyle</item>
</style>

<style name="FriendlyButtonStyle" parent="Widget.AppCompat.Button">
    <item name="android:textColor">@color/colorTitle</item>

</style>
在这里,如果您不想将属性更改为“NoActionBar”,那么也可以像上面那样在AndroidManifest.xml文件中设置它

<activity android:name=".MainActivity"
        android:theme="@style/Theme.AppCompat.NoActionBar"/>
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="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.google.firebase.codelab.friendlychat.MainActivity"
    android:id="@+id/coordinatorLayout">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabGravity="center"
            app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextColor="@android:color/white"
            app:tabIndicatorHeight="2dp"
            app:tabIndicatorColor="@android:color/white"/>

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


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.google.firebase.codelab.friendlychat.MainActivity">

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            app:adSize="BANNER"
            app:adUnitId="@string/banner_ad_unit_id">
        </com.google.android.gms.ads.AdView>

        <include
            layout="@layout/maincontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/adView"/>


        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:orientation="horizontal"
            android:layout_marginBottom="50dp">

            <ImageView
                android:id="@+id/addMessageImageView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@drawable/ic_add_black_24dp"/>

            <EditText
                android:id="@+id/messageEditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"/>

            <Button
                android:id="@+id/sendButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:enabled="false"
                android:text="SEND"/>

        </LinearLayout>

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"/>
    </RelativeLayout>

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

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/messageRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       />

</LinearLayout>

谢谢你的回复。但是,请给出一个实现我的问题代码的完整的工作答案:像这样有点混乱。我认为这是一个误解。我想指出,我需要为我的项目定制一个解决方案。我将在几分钟内更新这个问题,并链接到整个项目。修改的活动被称为MaunActudio。我将立即授予赏金并接受解决我的问题的答案。JONATANDOE纠正我,如果我错了,但是你想在中间有一个回收视图,在底部有一个编辑文本和一个发送按钮。top呢?谢谢你的回复。但是,请给出一个实现我的问题代码的完整的工作答案:像这样有点混乱。我认为这是一个误解。我想指出,我需要为我的项目定制一个解决方案。我将在几分钟内更新这个问题,并链接到整个项目。修改的活动被称为MaunActudio。我将立即授予赏金并接受解决我的问题的答案。JONATANDOE纠正我,如果我错了,但是你想在中间有一个回收视图,在底部有一个编辑文本和一个发送按钮。你提供的链接似乎是你想要做的事情的完整答案。你能告诉我们为什么这个答案不适合你吗?只是你的布局部分没有使用ProgressBar、MyOwnView等吗?@Gary99看起来不一样。一切都不对劲,秩序混乱等等@Gary99我用更多信息编辑了我的问题!您提供的链接似乎是对您试图做的事情的完整回答。你能告诉我们为什么这个答案不适合你吗?只是你的布局部分没有使用ProgressBar、MyOwnView等吗?@Gary99看起来不像sa
我一切都不对劲,秩序混乱等等@Gary99我用更多信息编辑了我的问题!谢谢你的回答!我想指出,我需要为我的项目定制一个解决方案。我将在几分钟内更新这个问题,并链接到整个项目。要修改的活动称为MainActivity。@JonathanDoe无法理解此问题。所以你只是用了这个例子,但它对你不起作用?@JonathanDoe你应该用我上面的例子,以得到预期的结果。用简单的视图是做不到的。我的意思是,我应该对问题中现有的项目链接做哪些修改,以便在我的主要活动中添加一个固定的选项卡栏?你明白了吗我试过了,但我无法用你的框架布局做到这一点。正如我所说,当问题解决后,我会立即奖励+100奖金。谢谢你的回答!我想指出,我需要为我的项目定制一个解决方案。我将在几分钟内更新这个问题,并链接到整个项目。要修改的活动称为MainActivity。@JonathanDoe无法理解此问题。所以你只是用了这个例子,但它对你不起作用?@JonathanDoe你应该用我上面的例子,以得到预期的结果。用简单的视图是做不到的。我的意思是,我应该对问题中现有的项目链接做哪些修改,以便在我的主要活动中添加一个固定的选项卡栏?你明白了吗我试过了,但我无法用你的框架布局做到这一点。正如我所说,当问题解决后,我会立即奖励+100奖金。@JonathanDoe如果我的回答符合你的要求,请接受我的回答want@JonathanDoe如果我的回答符合你的要求,请接受