如何使用视图寻呼机将底视图添加到协调器布局?

时间:2016-03-16 21:11:19

标签: android android-layout android-linearlayout android-coordinatorlayout

我想在Coordinator布局中添加底部视图,其中包含view pager,底部视图将位于由fragment加载的view pager之上且独立于此

我添加了linear layout

layout_gravity = "bottom"

但底视图linear layout根本没有显示

以下是我xml的{​​{1}}版面。

activity

3 个答案:

答案 0 :(得分:40)

正如@Dhawal在评论中指出的那样....解决方案是将LinearLayout completeBottomView包含在FrameLayout android:layout_gravity="bottom"

答案 1 :(得分:2)

Android CoordinatorLayout底部布局行为。

activity_bottom.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimaryDark"
            app:layout_scrollFlags="scroll|enterAlways"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#C0C0C0"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <com.example.android.coordinatedeffort.widget.FooterBarLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="bottom">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#007432"
            android:gravity="center"
            android:text="Footer View"
            android:textColor="@android:color/white"
            android:textSize="25sp" />
    </com.example.android.coordinatedeffort.widget.FooterBarLayout>

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

FooterBarLayout.java

FooterBarBehavior.java

答案 2 :(得分:-1)

这段代码对我有用。 将android.support.v7.widget.Toolbar的app:layout_scrollFlags="scroll|enterAlways"更改为app:layout_scrollFlags="scroll"属性。 更多详情here