Closed khrizt closed 6 years ago
@khrizt can you please help me with your layout code?
Of course @amarjain07 here I attach it and provide some explanation. The stickyHeader is a wrapper view that gets filled dynamically because the data it contains comes from an API. The other code are layouts that contain other data and images, if you need some extra clarification, please let me know.
<?xml version="1.0" encoding="utf-8"?>
<com.amar.library.ui.StickyScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:stickyHeader="@+id/stickyHeader">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bgColor">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_marginBottom="25dp"
android:background="@color/bgColor"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginEnd="@dimen/small_lateral_margin"
android:layout_marginLeft="@dimen/lateral_margin"
android:layout_marginRight="@dimen/small_lateral_margin"
android:layout_marginStart="@dimen/lateral_margin"
android:contentDescription="@string/img" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:paddingTop="12dp"
android:paddingBottom="5dp"
android:gravity="center_vertical"
android:layout_gravity="center_vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/ur_advisor"
android:textSize="14sp"
android:textColor="@color/greyLevel2"
android:layout_marginBottom="5dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="16sp"
android:textStyle="bold"
android:maxLines="2"
android:hint=""/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingEnd="10dp"
android:paddingRight="10dp"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:contentDescription="@string/phone"
android:src="@drawable/phone"
android:layout_marginBottom="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/call_text"
android:textColor="@color/colorPrimary"
android:textSize="14sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:contentDescription="@string/email"
android:src="@drawable/email"
android:layout_marginBottom="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/email"
android:textColor="@color/colorPrimary"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/stickyHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<LinearLayout
android:id="@+id/stickyHeaderWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:id="@+id/proposal_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/lateral_margin"
android:layout_marginRight="@dimen/lateral_margin"
android:layout_marginBottom="@dimen/lateral_margin"
android:layout_marginTop="40dp"
android:layout_marginStart="@dimen/lateral_margin"
android:layout_marginEnd="@dimen/lateral_margin"
android:orientation="vertical"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:textColor="@color/colorPrimary"
android:background="@drawable/button_clear_bg"
android:text="@string/offer_reject" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/lateral_margin"
android:orientation="vertical"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:padding="5dp"
android:textSize="18sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:textAppearance="@style/ButtonTextAppearance"
android:background="@drawable/button_bg" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/lateral_margin"
android:background="@color/bgColor"
android:layout_centerInParent="true"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginBottom="10dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg"
android:textAppearance="@style/button"
android:textSize="16sp"
android:layout_marginBottom="15dp"/>
</LinearLayout>
</RelativeLayout>
</com.amar.library.ui.StickyScrollView>
@khrizt Can you please try with a simple layout without dynamic data and then try building upon that. You can also refer to the sample project in the repo, and then modify it as per your need. https://github.com/amarjain07/StickyScrollView/blob/master/sample/src/main/res/layout/activity_main.xml
Well the thing is that this works in Lollipop and superior versions, only fails in pre-Lollipop devices. I can try other layouts but I'm positive they will work Ok. That's why I found strange that worked ok in all devices except pre-lollipop ones.
Hi, I am facing issue in sticky scroll view. I am using viewpager and spinner in my layout on swiping pages of pager or on opening drop down for spinner the footer view changes its position. it disappears and appears on another position. I have also tried in your sample,same issue is there. Please suggest me fix for this.
I think you have this problem because your header is a child of LinearLayout. On pre-Lollipop devices the library calls view#bringToFront() method which works bad inside LinearLayout. Try to use other layout - ConstraintLayout or RelativeLayout. It helped me when I encountered the same problem.
@IraMMR Thanks for the reply, unfortunately we are on process of re-designing the app and the sticky header is not a design need anymore. But what you say makes a lot of sense and would probably fix the issue. Thanks
Hi,
Thanks for developing this library, it's great and simple to use. Really good work.
I'm using your library for my app and in a Samsung S3 device (with Android 4.3) and after the first scroll the view gets positioned on bottom and never recovers its original position. Here's an screenshot:
The view that should be sticky is the one with prices at the end of the image. If you could have a look, that'd be great. Thanks!