android - 粘性布局和向下滚动
问题描述
我在滚动视图中实现粘性布局,搜索栏很好地粘住,但我需要从滚动视图的任何地方向下滚动搜索栏和邀请按钮,目前搜索栏粘在顶部,但它不会从我必须滚动到顶部的任何位置向下滚动. 我想要像谷歌Play商店搜索面板这样的功能,如果我向上滚动搜索栏和顶部,当我向下滚动时,我也可以看到搜索栏和邀请按钮,我的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gray_bg">
<com.mtg.workapp_v2.listing.CommonViews.StickyScrollView
android:id="@+id/stickyScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/btnInviteFromPhoneContacts"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white"
android:focusableInTouchMode="true">
<TextView
android:id="@+id/textInviteFromPhoneContacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/id_invite_from_phone_contacts"
android:textAllCaps="true"
android:textColor="@color/row_trash_bg"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:layout_width="11dp"
android:layout_height="11dp"
android:layout_centerVertical="true"
android:layout_marginStart="15dp"
android:layout_toEndOf="@+id/textInviteFromPhoneContacts"
android:contentDescription="@null"
android:src="@drawable/expand_icon_v2" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layoutSearch"
android:layout_width="match_parent"
android:layout_height="45dp"
android:tag="sticky"
android:background="@android:color/white"
android:layout_marginTop="2dp"
android:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:background="@drawable/search_bar_bg">
<EditText
android:id="@+id/editSearch"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toEndOf="@+id/imgSearch"
android:layout_toStartOf="@+id/imageNext"
android:background="@android:color/transparent"
android:gravity="start|center_vertical"
android:hint="@string/id_search_messages"
android:singleLine="true"
android:text=""
android:textColor="@android:color/black"
android:textColorHint="@color/text_gray_color"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageNext"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:contentDescription="@null"
android:padding="3dp"
android:src="@drawable/right_arrow" />
<ImageView
android:id="@+id/imgSearch"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginStart="20dp"
android:contentDescription="@null"
android:padding="3dp"
android:src="@drawable/search_icon_grey" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/newMessageRecycleView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:focusable="false" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:visibility="gone"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/btnSelectExistingWorkAppGroups"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white">
<TextView
android:id="@+id/textSelectExistingWorkAppGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/id_select_workapp_group"
android:textAllCaps="true"
android:textColor="@color/row_trash_bg"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imgSelectGroups"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginStart="15dp"
android:layout_alignParentStart="true"
android:contentDescription="@null"
android:src="@drawable/expand" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:background="@color/gray_bg" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerExistingWorkAppGroups"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:focusable="false" />
<RelativeLayout
android:id="@+id/btnSelectExistingWorAppContacts"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/white">
<TextView
android:id="@+id/textSelectExistingWorkAppContacs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/id_select_workapp_contacts"
android:textAllCaps="true"
android:textColor="@color/row_trash_bg"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/imgSelectContacts"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginStart="15dp"
android:layout_alignParentStart="true"
android:contentDescription="@null"
android:src="@drawable/expand" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:background="@color/gray_bg" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerExistingWorkAppContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:focusable="false" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</com.mtg.workapp_v2.listing.CommonViews.StickyScrollView>
</RelativeLayout>
解决方案
推荐阅读
- javascript - 通过复制创建对象数组
- c# - 持久功能:以扇出模式获取失败的任务
- watchkit - watchOS中的后台数据任务
- javascript - 将多个 DIV 导出为单个 pdf
- typescript - 我可以从我的库中导出对全局命名空间的修改吗?
- javascript - 如何在条件内的另一个组件下方的无状态组件上呈现函数?
- java - 根据日期找到时间并希望将其从字符串转换为整数
- operating-system - HMI 设备上应该有 RTOS 吗?
- python - 使用 python3.6 和 BeautifulSoup。我得到的是hrefs,但我无法下载它们
- apache-spark - 在运行时为 spark 传递参数