带ImageView和Recycler视图的NestedScrollView [英] NestedScrollView with ImageView and Recycler view

查看:90
本文介绍了带ImageView和Recycler视图的NestedScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Recycler视图在imageview中滚动,而imageview保持静止.我的要求是在滚动recyclerview时同时滚动两个视图.我编写的xml如下:

The Recycler view gets scrolled inside imageview and imageview stays stationary.My requirement is to scroll both the views when recyclerview is scrolled.The xml I have written is given below:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        <LinearLayout
            android:gravity="center_vertical"
            android:id="@+id/profileLayout"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:background="@color/primary_color"
            android:orientation="vertical"
            android:padding="10dp">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profile_image"
                android:layout_width="96dp"
                android:layout_height="96dp"
                android:src="@drawable/profile_user"
                app:border_color="#ffffff"
                app:border_width="2dp" />

            <TextView
                android:id="@+id/fullNameTextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:textColor="@color/primary_color" />
        </LinearLayout>


    <android.support.v7.widget.RecyclerView
            android:id="@+id/drawerList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/myDrawerBackground"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </LinearLayout>

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

如何实现这种滚动?

推荐答案

我认为您应该为此目的使用CoordinatorLayout,以便将通函ImageView放入CollapsingToolbarLayout&中.您也可以使用它来设置标题,而不是由fullNameTextView id指定的TextView,如下所示:

I think you should use CoordinatorLayout for this purpose where you can put your circular ImageView inside CollapsingToolbarLayout & also you can use it to set your title instead of your TextView which is specified by fullNameTextView id as below:

Xml:

<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">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/collapsible_app_bar_height"
        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:background="@drawable/gradient_banner"
            app:contentScrim="@color/background_content_frame"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profile_image"
                android:layout_width="96dp"
                android:layout_height="96dp"
                android:src="@drawable/profile_user"
                app:border_color="#ffffff"
                app:border_width="2dp"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/collapsible_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_collapseMode="pin"/>

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

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

     <android.support.v7.widget.RecyclerView
            android:id="@+id/drawerList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/myDrawerBackground"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

Java:

 CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
 collapsingToolbar.setTitle("Title");

参考: https://guides.codepath.com/android/Handling-使用CoordinatorLayout滚动

这篇关于带ImageView和Recycler视图的NestedScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆