android - 是否可以在没有折叠工具栏布局的情况下使用 coordinatorlayout 进行简单的图像查看器视差?

标签 android coordinator-layout

你好,假设我有一个包含以下内容的布局

    <ScrollView
        android:id="@+id/scroll"
        android:layout_below="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/button">

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

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="240dp"
            android:scaleType="centerCrop"
            android:src="@drawable/android" />
        <View android:id="@+id/anchor"
            android:layout_width="match_parent"
            android:layout_height="240dp" />
        <TextView
            android:id="@+id/body"
            android:layout_below="@+id/anchor"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:textColor="@android:color/black"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:text="@string/sample" />
    </RelativeLayout>

    </ScrollView>

是否可以使用协调器布局使 ImageView 在向上或向下滚动时以 ScrollView 的一半速度移动。

最佳答案

可能不是 CoordinatorLayout 的预期用途,但我相信我通过执行以下操作达到了预期效果:

enter image description here

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="300px"
    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:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/myToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            <TextView android:id="@+id/textViewTitle"  
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
            </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

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

    <!-- my content that scrolls over the backdrop image -->

</android.support.v4.widget.NestedScrollView>

关于android - 是否可以在没有折叠工具栏布局的情况下使用 coordinatorlayout 进行简单的图像查看器视差?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31387730/

相关文章:

android - 将带有 Android Things 的 Raspberry PI 3 连接到 Arduino

android - 人脸识别使用Opencv4Android SDK教程?

java - 检测垂直滚动已经结束并且用户正在拉动

android - CoordinatorLayout 内容子项与 BottomNavigationView 重叠

android - 将所有布局包装在 CoordinatorLayout 中是一种好习惯吗?

android - 需要为某些 fragment 禁用 CollapsingToolbarLayout 上的展开

java - android - 从/res/raw文件夹中检索所有文件作为文件类型

安卓词典应用

android - 如何将协调器布局包装在 LinearLayout 中?

android - 适配器的内容已经改变但是ListView没有收到通知