【问题标题】:Collapsing card view when Recycler View scroll downRecycler View 向下滚动时折叠卡片视图
【发布时间】:2017-08-21 11:57:30
【问题描述】:

如何将卡片放在工具栏下方并折叠它,直到我向下滚动时它消失并在我向上滚动时重新打开

我将 Xamarin.Android 与设计库一起使用

这是我的 AXML 代码:

    <?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/coordinatorLayoutMainLayoutPublicationsLayout"
    android:fitsSystemWindows="true">

  <android.support.design.widget.AppBarLayout
         android:id="@+id/main.appbar"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
          android:id="@+id/collapsing_toolbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:fitsSystemWindows="true"
          app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">

      <android.support.v7.widget.CardView
             xmlns:card_view="http://schemas.android.com/apk/res-auto"
             android:id="@+id/card_view"
             android:layout_gravity="center"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             app:cardCornerRadius="4dp"
             app:cardElevation="4dp"
             app:cardUseCompatPadding="true">

        <Button
         android:layout_width="match_parent"
         android:layout_height="150dp"
         android:text="BOBOBOBOBOBOB"
         app:layout_scrollFlags="scroll|enterAlways"/>

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

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

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

    <android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeContainerPublicationsLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.RecyclerView
      android:id="@+id/recyclerViewPublicationsLayout"
      android:scrollbars="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

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

  <android.support.v7.widget.Toolbar
        android:id="@+id/toolbarPublicationsLayout"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

  <android.support.design.widget.FloatingActionButton
    android:id="@+id/fabPublicationsLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:src="@drawable/icon_add_fab"
    android:layout_margin="15dp" />

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

输出视图是这样的:

Screenshot of the view

【问题讨论】:

    标签: android android-recyclerview xamarin.android android-cardview android-design-library


    【解决方案1】:

    经过几个小时的搜索,我找到了解决方案,在 NestedScrollView 中制作 recyclerview 和 cardview

    <?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"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
        android:id="@+id/linearLayoutMainLayout">
    
        <android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary" />
    
    
    
    
    <android.support.design.widget.CoordinatorLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/coordinatorLayoutMainLayout">
    
    
    
      <android.support.v4.widget.SwipeRefreshLayout
          android:id="@+id/swipeContainer"
          android:layout_width="match_parent"
          android:layout_height="match_parent"  >
    
        <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
    
             <android.support.v7.widget.CardView 
       android:id="@+id/card_view"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       app:cardCornerRadius="4dp"
       app:cardElevation="4dp"
       app:cardUseCompatPadding="true">
    
    
        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:padding="8dp">
    
          <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textStyle="bold"
            android:id="@+id/textView1" />
          <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView2" />
          <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView3" />
          <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/textView4" />
          <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button" />
    
        </LinearLayout>
    
      </android.support.v7.widget.CardView>
    
             <android.support.v7.widget.RecyclerView
              android:id="@+id/recyclerView"
              android:scrollbars="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:nestedScrollingEnabled="false"/>
    
        </LinearLayout>
    
    </android.support.v4.widget.NestedScrollView>
    
    
          </android.support.v4.widget.SwipeRefreshLayout>
    
    <android.support.design.widget.FloatingActionButton
          android:id="@+id/fab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:src="@drawable/icon_add_fab"
        android:layout_margin="15dp"/>
    
    </android.support.design.widget.CoordinatorLayout>
    
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-24
      • 2017-11-30
      相关资源
      最近更新 更多