简体   繁体   English

带ImageView和Recycler视图的NestedScrollView

[英]NestedScrollView with ImageView and Recycler view

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: Recycler视图在imageview中滚动并且imageview保持静止。我的要求是在滚动recyclerview时同时滚动两个视图。我编写的xml如下:

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

How do I achieve such type of scrolling? 如何实现这种滚动?

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: 我认为您应该为此使用CoordinatorLayout ,将圆形ImageView放在CollapsingToolbarLayout ,也可以使用它来设置标题,而不是由fullNameTextView id指定的TextView ,如下所示:

Xml: 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: Java:

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

Reference: https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout 参考: https : //guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout

<RelativeLayout     
    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:background="@color/cardview_light_background"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView"
        tools:ignore="UselessParent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            tools:ignore="ExtraText"
            android:weightSum="1" >

            <ImageView
                android:id="@+id/image_offer"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:scaleType="fitXY"
                app:srcCompat="@drawable/kuhnyamain"
                tools:ignore="ContentDescription" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_marginTop="250dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </android.support.v7.widget.RecyclerView>

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NestedScrollView内的回收者视图 - Recycler View inside a NestedScrollView 具有CoordinatorLayout的NestedScrollView内的回收者视图 - Recycler view Inside NestedScrollView with CoordinatorLayout Recycler视图内的NestedScrollview不滚动 - NestedScrollview inside a Recycler view not scrolling ImageView的回收站视图位置底部 - Recycler View Position Bottom of ImageView 当回收器视图放在nestedscrollview中时,PagedListAdapter获取所有项目 - PagedListAdapter fetching all the items when recycler view is placed inside nestedscrollview NestedScrollView 中的 Recycler 视图导致滚动从中间开始 - Recycler view inside NestedScrollView causes scroll to start in the middle 在 NestedScrollView 中,Recycler View 加载大数据时非常慢 - Recycler View loading very slow for large data when inside NestedScrollView Recycler View无法使用ImageView,但可以使用ImageView + TextView - Recycler View not working with ImageView but work with ImageView+TextView 如何在放置在约束布局内的 NestedScrollView 中添加 Recycler View,尝试添加回收器视图但未成功 - How to add Recycler View inside the NestedScrollView which is placed inside a constraint layout, tried to add recycler view but not getting succesful 在nestedscrollview中滚动多个水平回收器视图,它们之间带有视图分隔符 - scroll multiple horizonal recycler-view with view-separator between them inside nestedscrollview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM