折叠式工具栏布局和约束布局

5
我正在努力创建可折叠的图片头部,同时还要使用ConstraintLayout进行布局设计,我的设计如下所示:

enter image description here

目前,个人资料照片是ConstraintLayout的一部分,因为它需要Guideline约束,但不幸的是被AppBarLayout覆盖。
有什么想法可以实现吗?找不到有关我这种布局组合的任何来源.....
<?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:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/playerViewBg"
        android:fitsSystemWindows="false">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/bgIV"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/header_bg" />

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

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

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/playerIV"
            android:layout_width="177dp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="62dp"
            android:adjustViewBounds="true"
            android:scaleType="fitCenter"
            android:src="@drawable/profilePic"
            app:layout_constraintEnd_toStartOf="@+id/guideline2"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toStartOf="@+id/guideline"
            app:layout_constraintTop_toTopOf="parent" />

        <!-- Other content -->

        <android.support.constraint.Guideline
            android:id="@+id/guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.27" />

          <android.support.constraint.Guideline
            android:id="@+id/guideline2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.73" />

    </android.support.constraint.ConstraintLayout>

</android.support.design.widget.CoordinatorLayout>
2个回答

4
以下是我工作布局的片段:
请确保您没有在ConstraintLayout中将任何子视图高度设置为与父视图匹配(0 dp),并且对于ScrollView,请使用android:fillViewport="true"。如果有任何疑问,请问我。
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:fitsSystemWindows="false">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ImageView
                android:id="@+id/ivImagec"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/_90sdp"
                android:contentDescription="@string/no_des"
                android:scaleType="centerCrop"
                app:srcCompat="@drawable/outdoorgames" />


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

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/_90sdp"
        android:fillViewport="true">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/cvLayout"
            android:animateLayoutChanges="true">
                 ....
        </android.support.constraint.ConstraintLayout>

2
我最近开始思考这个问题。根据两位Android Studio开发人员在此次讲座中的讲话:https://www.youtube.com/watch?v=8lAXJ5NFXTM(21分28秒处),可以肯定地说,使用ConstraintLayout完全替换CollapsingToolbarLayout是可行的。请看下面的演示图片:Nicol's demo

1
我会看一下,它看起来很有前途 :) 实际上,我已经通过将约束移到折叠处解决了这个问题。 - Jocky Doe
@JockyDoe,你能再详细解释一下吗? - LOG_TAG
@JockyDoe,是的,在上述的YouTube讲座中,他们没有分享任何演示文稿/演示中所解释的演示示例的源代码!(你可以回答自己的问题:);) - LOG_TAG
@LOG_TAG 好吧,我没有按照YouTube视频中的方法解决问题,但如果你感兴趣的话,我可以发布我想出来的解决方案。你的目标是使用折叠栏缩小图像吗? - Jocky Doe
1
@ibhavikmakwana 是的,来自你的repo :D Constraint-Layout-Animations,非常棒的工作! - LOG_TAG
显示剩余5条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接