Search code examples
androidandroid-scrollview

Dock ImageView on top of screen while scrolling


This is my layout file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">

<include
    android:id="@+id/appBar"
    layout="@layout/app_bar" />

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/appBar"
    android:layout_centerHorizontal="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView_CoverImage"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_centerHorizontal="true"
            android:scaleType="fitXY" />

        <ScrollView
            android:id="@+id/scrollView_TextView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal">

            <TextView
                android:id="@+id/textView_Description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#ffffff" />
        </ScrollView>

    </LinearLayout>
</ScrollView>

I got a ImageView and a TextView inside a ScrollView and the TextView is in another ScrollView. My Question is, Is it possible to dock the ImageView on top of screen while scrolling up (The bottom 25% of the image should be visible to user) and the TextView should be scrollable to see the rest of the texts.


Solution

  • I suggest you take a look at NestedScrollView in the support library.

    It seems a bit odd that you would even need to nest two scroll views in your design. Perhaps you should think about making a new fragment to hold the extra information. You shouldn't really have so much information in one viewgroup that you are forced to nest two scrollviews.

    Good luck!