kmshack / Android-ParallaxHeaderViewPager

DEPRECATED
Apache License 2.0
1.39k stars 336 forks source link

Image is not displayed initially #7

Closed francophong closed 10 years ago

francophong commented 10 years ago

Hi,

I edited the layout a bit for my project's purpose as below: <FrameLayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="@dimen/header_height">

    <com.flavienlaurent.notboringactionbar.KenBurnsView
        android:id="@+id/header_picture"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/picture0" />

// I replace the imageview with a custom view <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"

        <ImageView
            android:id="@+id/header_logo"
            android:layout_width="@dimen/header_logo_size"
            android:layout_height="@dimen/header_logo_size"
            android:layout_centerInParent="true"
            android:layout_alignParentTop="true"
            android:paddingTop="15dp"
            />

        <ImageView
            android:id="@+id/header_logo_hide"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/header_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/header_logo"
            android:layout_centerHorizontal="true
            android:paddingTop="20dp"
            android:textSize="20dp"
            android:textStyle="bold" />
  </RelativeLayout>

</FrameLayout>

and I use this layout in a fragment, so the code was changed a bit to work in fragment

Issue: when open the fragment, the header_logo is not displayed unless I make a initial action like scroll or touch or click.

Please help to advise me.

francophong commented 10 years ago

I debugged and found the issue. The calculation of ScaleX and ScaleY return "NaN" by somehow. Solution: change the calculation float scaleX = 1.0F + interpolation * (mRect2.width() /360.0F - 1.0F); It worked as a charm