gpt4 book ai didi

Android AppBarLayout TabLayout

转载 作者:行者123 更新时间:2023-11-29 23:31:45 29 4
gpt4 key购买 nike

我尽量让红色布局滚动,这样他就隐藏了,TabLayout 就留在了最上面

我需要红色布局来为我填充圆形头像的高度。我尝试将TabLayout滚动到顶部,红色布局继续滚动隐藏?

无法发送图片,请点击链接查看演示。

https://shejiao-v2.oss-cn-shenzhen.aliyuncs.com/ezgif.com-optimize.gif

这是我的代码

 <?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:id="@+id/coordinator_lay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="190dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp"
app:layout_behavior="@string/appbar_spring_behavior">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:scrimVisibleHeightTrigger="95dp"
app:titleEnabled="false">

<ImageView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@mipmap/default_cover_bg"
app:layout_collapseMode="parallax" />

<android.support.v7.widget.Toolbar
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:layout_alignParentTop="true"
android:textSize="11sp"
app:contentInsetStart="?actionBarInsetStart"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
tools:ignore="SmallSp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/toolbar_avatar"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/default_avatar"
android:visibility="gone"
app:civ_border_color="#D6D6D6"
app:civ_border_width="1dp"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|center_horizontal"
app:layout_behavior="android.support.design.widget.CircleImageViewBehavior" />

<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textColor="@android:color/white"
android:textSize="18sp"
android:visibility="gone" />

</LinearLayout>

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

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

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

<com.thsseek.shejiao.ui.widget.CircleImageViewFAB
android:id="@+id/avatar"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="centerCrop"
android:src="@mipmap/default_avatar"
app:civ_border_color="#D6D6D6"
app:civ_border_width="2dp"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|center_horizontal" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?colorPrimary"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorAccent" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.kekstudio.dachshundtablayout.DachshundTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ddIndicatorColor="@android:color/black"
app:tabGravity="center"
app:tabMode="fixed"
app:tabPaddingStart="0dp" />

</LinearLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

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

我怎样才能改变这个来达到这个效果?

最佳答案

取而代之的是 LinearLayout 的偏移量,只需使用 View。在 CollapsingToolbarLayout 中将 CircleImageViewFAB(avatar) 和 View(offset) 移动到 imageView(background) 之后 Toolbar

之前

设计:

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

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
...>

<!--background image-->
<ImageView
android:id="@+id/cover"
... />

<!--big avatar image-->
<com.thsseek.shejiao.ui.widget.CircleImageViewFAB
android:id="@+id/avatar"
... />

<!-- offset with background for big avatar -->
<View
android:id="@+id/offset"
... />

<android.support.v7.widget.Toolbar
android:id="@+id/actionbar"
... />

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?colorPrimary"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.kekstudio.dachshundtablayout.DachshundTabLayout
android:id="@+id/tabs"
... />

</LinearLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
... />
</LinearLayout>

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

关于Android AppBarLayout TabLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52570964/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com