[英]How do I place toolbar below collapsingtoolbarlayout when expanded?
I have the following code below on which I'm trying to make a collapsible toolbar that will make the toolbar which has a linearlayout inside, to stick to the bottom part of the layout when expanded. 我在下面的代码中尝试制作一个可折叠的工具栏,该工具栏将使内部具有linearlayout的工具栏在展开时保持在布局的底部。
I have been moving parts/layouts all around for several hours trying to make it stick to the bottom and still show at the appbar even when closed/pushed up but I cant make it show up as I intended. 我一直在移动零件/布局几个小时,试图使其粘在底部,即使关闭/推入时仍显示在应用栏上,但我无法按预期显示它。
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:popupTheme="@style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/ivProfileAvatar"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/profile_image" />
<Space
android:layout_width="match_parent"
android:layout_height="16dp" />
<TextView
android:id="@+id/tvUserUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="SomeName"
android:textColor="@android:color/white"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="UniversityName"
android:textColor="@android:color/white"
android:textSize="16dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="tvUserStatus"
android:textColor="@android:color/white"
android:textSize="16dp" />
<Space
android:layout_width="match_parent"
android:layout_height="16dp" />
<Button
android:id="@+id/btnEditProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/btn_gradient_blue"
android:paddingEnd="48dp"
android:paddingStart="48dp"
android:text="Edit Profile"
android:textAllCaps="false"
android:textColor="@android:color/white" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<android.support.design.widget.TabLayout
android:id="@+id/tabsProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabBackground="@null"
app:tabGravity="center"
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="2dp">
<android.support.design.widget.TabItem
android:id="@+id/tabProfileMyLikes"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.TabItem
android:id="@+id/tabProfileMyPosts"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.design.widget.TabLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
You are using TabLayout
inside Toolbar
and that's not a good design and wrong (i should say). 您正在Toolbar
TabLayout
使用TabLayout
,这不是一个好的设计,而且是错误的(我应该说)。
Instead, try something like this: 而是尝试这样的事情:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
<android.support.design.widget.TabLayout
android:id="@+id/tabsProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabBackground="@null"
app:tabGravity="center"
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="2dp">
<android.support.design.widget.TabItem
android:id="@+id/tabProfileMyLikes"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.TabItem
android:id="@+id/tabProfileMyPosts"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.design.widget.TabLayout>
To make a view pinned or stick somewhere, using app:layout_collapseMode="pin"
will help or instead, add the view to CoordinatorLayout
like FloatingActionButton
position to make it stick in the bottom and set: android:gravity
to bottom
. 要使视图固定或粘贴在某处,请使用app:layout_collapseMode="pin"
来帮助或代替,将视图添加到CoordinatorLayout
例如FloatingActionButton
位置,使其固定在底部,并将android:gravity
设置为bottom
。
Use the below code I hope it will help you 使用以下代码,希望对您有所帮助
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Title"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
app:titleEnabled="false">
<include layout="@layout/record_description_header" />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_marginTop="50dp"
android:scaleType="centerCrop"
android:src="@drawable/bcslogo2"
app:layout_collapseMode="parallax" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.