Jigar Makwana Jigar Makwana - 6 months ago 125
Android Question

enable click event on parallax ListView with sticky header in android

I have implemented a listView with parallax effect with a sticky listview in android,I have used the following link for the reference and have implemented successfully this thing,But I am facing an issue on clicking the background images above the listheader,Can anybody help me to figure it out and can I find the click events of childviews of listitems

ref Link : http://javatechig.com/android/listview-header-parallax-with-sticky-view-in-android

i can't post my code as its too large to post,But if still it is needed i can post some parts.

Answer

I saw reference link @Jigar Makwana posted. You will not get click event on imageView because on imageView there is "Space control" used inside the listview header layout, And below it that heroimageView(ImageView). So when you click on that header part that is not imageView it is Space widget. Even though space control cannot get click event you have to use simple View or use that imageView inside listview header Layout instead of space. But it is not proper way to implement this design & functionality. If you want to do it in proper way follow below links.

Your reference link is not good example of parallex with sticky layout. Proper example are Handling Scrolls with CoordinatorLayout & Collapsing Toolbar Layout

In that you can use CoordinatorLayout inside imageView you want click event to handle and make one layout containing your headingText and add it as listview header.That's it and works perfectly and you will never see bug again.

Code is simple:

    <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/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="0dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_transparent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:minHeight="?attr/actionBarSize"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:id="@+id/relativeLayout_main_profile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="7dp"
                android:animateLayoutChanges="true"
                app:layout_collapseParallaxMultiplier="0.7"
                app:layout_collapseMode="parallax"
                tools:context="com.mazkara.user.activity.ProfileActivity">
               <ImageView
                android:id="@+id/heroImageView"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:background="@drawable/wallpaper"
                android:scaleType="fitCenter" />
            </RelativeLayout>
// only if you use toolbar then specify here your toolbar start
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_main_transparent"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/transparent"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:titleTextAppearance="@color/white">
            </android.support.v7.widget.Toolbar>    //toolbar end 
        </android.support.design.widget.CollapsingToolbarLayout>
       <TextView
        android:id="@+id/stickyView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#222"
        android:gravity="center_vertical"
        android:paddingLeft="10dp"
        android:text="Heading1"
        android:textColor="#fff"
        android:textSize="20sp"
        android:layout_gravity="bottom"
        app:layout_collapseMode="pin"
        android:textStyle="bold" />

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


     <android.support.v7.widget.RecyclerView
    android:id="@+id/design_bottom_sheet"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/bottom_sheet_behavior">
</android.support.design.widget.CoordinatorLayout>

That's it.

Comments