Содержимое выше RecyclerView с эффектом параллакса в Android - PullRequest
0 голосов
/ 16 декабря 2018

Как описано в 1 , я хочу реализовать макет, где половина экрана составляет некоторую Content, например LinearLayout, включая круговую диаграмму.Другая половина экрана должна быть RecyclerView, включая CardView, который я уже реализовал.При прокрутке вверх должен быть эффект параллакса, скрывающий Content до AppBar.

Я пытался использовать LinearLayouts (где один включает Content, а другой включает Recyclerview) с weightSum, но он не работал должным образом.

Как я могуреализовать это правильно?

Дизайн, который я хочу реализовать в моем приложении

1 Ответ

0 голосов
/ 16 декабря 2018

Я согласен с другим ответом здесь.Взгляните на документы.

Но для быстрого исправления:

Сначала импортируйте Android Design Library

implementation 'com.android.support:design:28.0.0'

У вас уже должны быть CardView и RecyclerViewбиблиотеки

implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'

Затем реализуйте этот код

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main3Activity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing"
            android:layout_width="match_parent"
            android:layout_height="350dp"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="#0e0d0e"
            app:expandedTitleTextAppearance="@android:color/transparent">

            <!--these views are only to illustrate the imp. tags -->
            <!--that you need to implement in your views-->
            <!--in the "Component" area-->

            <!--start example-->

            <ImageView
                android:id="@+id/iv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@null"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                app:title="Title"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="parallax"/>

            <!--end example-->

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

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


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

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

            <!--implement the RecyclerView here-->

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical">

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


        </LinearLayout>

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

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