代码之家  ›  专栏  ›  技术社区  ›  Mkurbanov

RecyclerView标题或俯视图

  •  0
  • Mkurbanov  · 技术社区  · 7 年前

    请帮帮我!

    如何在RecyclerView顶部添加视图。

    此图像: https://blog.iamsuleiman.com/wp-content/uploads/2017/08/pagination-4-recyclerview-multiple-viewtypes-header.png

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView 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="@drawable/pattern"
        android:fillViewport="true"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context=".MainActivity"
        tools:showIn="@layout/app_bar_main">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    
            <ImageView
                android:id="@+id/main_image_slider"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/line" />
    
            <android.support.v4.widget.SwipeRefreshLayout
                android:id="@+id/main_swipe"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rc"
                    android:layout_width="match_parent"
                    android:layout_height="500dp"
                    android:scrollbars="none" />
            </android.support.v4.widget.SwipeRefreshLayout>
        </LinearLayout>
    
    </android.support.v4.widget.NestedScrollView>
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   mrmeaaan    7 年前

    欢迎来到Stackoverflow。

    我觉得很难理解你的问题。从我的角度来看,您希望在recyclerview的上方(顶部)添加另一个图像。另外,您不需要NestedScrollView。请尝试以下操作:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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="@drawable/pattern"
    android:fillViewport="true"
    android:orientation="vertical"
    tools:context=".MainActivity"
    tools:showIn="@layout/app_bar_main">
    <ImageView
                android:id="@+id/main_image_slider"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/line" />
    <ImageView
                android:id="@+id/ivNew1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/line" />
    <ImageView
                android:id="@+id/ivNew2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/line" />
    
        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/main_swipe"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <android.support.v7.widget.RecyclerView
                android:id="@+id/rc"
                android:layout_width="match_parent"
                android:layout_height="500dp"
                android:scrollbars="none" />
        </android.support.v4.widget.SwipeRefreshLayout>
    
    </LinearLayout>