john
john

Reputation: 150

Wrong scrolling of floating action button

I have two FABs (FAB: floating action button) on the top of an ImageView and one on the right bottom of another ImageView

My problem is that I'm trying to make the top FAB to be fixed and the other one scrollable. However, I'm getting results contrary to what I wanted. I tried taking one FAB out of ScrollView but it still doesn't work as both the FABs will initially be over the ImageView.

My layout:

<android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true"
    android:background="@color/colorPrimary"
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <android.support.v4.view.ViewPager
            android:id="@+id/detail_page_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
            <LinearLayout
                android:id="@+id/SliderDots"
                android:orientation="horizontal"
                android:layout_gravity="bottom"
                android:layout_marginBottom="10dp"
                android:gravity="center_vertical|center_horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
            <android.support.v7.widget.CardView
                android:layout_width="50dp"
                android:layout_height="50dp"
                app:cardBackgroundColor="@color/White"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                app:cardCornerRadius="60dp">
            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                app:fabSize="normal"
                android:src="@drawable/ic_arrow_back_black_24dp"
                android:adjustViewBounds="true"
                android:layout_gravity="top"/>
            </android.support.v7.widget.CardView>
        </FrameLayout>
        <LinearLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/viewB"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary"
            android:orientation="vertical">

            <com.ct.listrtrial.Custom.CustomTextViewMedium
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/detail_page_text1"
                android:textSize="20sp"
                android:textColor="@color/White"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"/>
            <com.ct.listrtrial.Custom.CustomTextViewMedium
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/detail_page_text2"
                android:textColor="@color/White"
                android:textSize="16sp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"/>
            <com.ct.listrtrial.Custom.CustomTextViewMedium
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/detail_page_text3"
                android:textColor="@color/White"
                android:justificationMode="inter_word"
                android:layout_marginStart="10dp"
                android:layout_marginTop="10dp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="10dp"
                android:layout_marginRight="10dp">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                   android:paddingLeft="10dp"
                    app:srcCompat="@drawable/ic_local_phone_black_24dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/mobile_number"
                    android:textColor="@color/White"
                    android:textSize="16sp"
                    android:paddingLeft="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/rating"
                    android:textSize="16sp"
                    android:textColor="@color/White"
                    android:paddingLeft="120dp"/>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_star_black_24dp"
                    android:paddingLeft="10dp"/>
            </LinearLayout>
            <FrameLayout
                android:layout_marginTop="20dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="300dp"
                    android:layout_height="100dp"
                    android:background="@drawable/detail_pager_button"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/black"
                    android:text="Entry Via GuestList"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="10dp"
                    android:textSize="17sp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/black"
                    android:textSize="14sp"
                    android:text="@string/dummy_text"
                    android:layout_marginTop="40dp"
                    android:layout_marginLeft="10dp"/>
                <ImageView
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    app:srcCompat="@drawable/ic_keyboard_arrow_right_black_24dp"
                    android:layout_marginLeft="250dp"
                    android:layout_marginTop="20dp"/>
            </FrameLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="10dp">
                <com.ct.listrtrial.Custom.CustomTextViewMedium
                    android:layout_width="0dp"
                    android:layout_weight="8"
                    android:layout_height="wrap_content"
                    android:text="@string/event_list_text"
                    android:layout_marginLeft="15dp"
                    android:textSize="25sp"
                    android:textColor="@color/White"/>
                <ImageView
                    android:layout_width="0dp"
                    android:layout_weight="2"
                    android:layout_marginLeft="180dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="5dp"
                    android:layout_height="wrap_content"
                    android:scaleType="centerCrop"
                    android:adjustViewBounds="true"
                    android:src="@drawable/more_button"/>
            </LinearLayout>
            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none">

                <LinearLayout
                    android:id="@+id/llDateContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:orientation="horizontal"
                    android:showDividers="middle">

                </LinearLayout>
            </HorizontalScrollView>

            <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:scrollbars="none">

                <LinearLayout
                    android:id="@+id/llTimeContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"

                    android:gravity="center_horizontal"
                    android:orientation="horizontal"
                    android:showDividers="middle">

                </LinearLayout>


            </HorizontalScrollView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="10dp">
                <com.ct.listrtrial.Custom.CustomTextViewMedium
                    android:layout_width="0dp"
                    android:layout_weight="8"
                    android:layout_height="wrap_content"
                    android:text="@string/choose_table_text"
                    android:layout_marginLeft="15dp"
                    android:textSize="25sp"
                    android:textColor="@color/White"/>
                <ImageView
                    android:layout_width="0dp"
                    android:layout_weight="2"
                    android:visibility="gone"
                    android:layout_marginLeft="180dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="5dp"
                    android:layout_height="wrap_content"
                    android:scaleType="centerCrop"
                    android:adjustViewBounds="true"
                    android:src="@drawable/more_button"/>
            </LinearLayout>
            <android.support.v7.widget.RecyclerView
                android:layout_marginTop="20dp"
                android:id="@+id/event_list_recyclerview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            </android.support.v7.widget.RecyclerView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="10dp">
                <com.ct.listrtrial.Custom.CustomTextViewMedium
                    android:layout_width="0dp"
                    android:layout_weight="8"
                    android:layout_height="wrap_content"
                    android:text="@string/persons_list_text"
                    android:layout_marginLeft="15dp"
                    android:textSize="25sp"
                    android:textColor="@color/White"/>
                <ImageView
                    android:layout_width="0dp"
                    android:layout_weight="2"
                    android:visibility="gone"
                    android:layout_marginLeft="180dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="5dp"
                    android:layout_height="wrap_content"
                    android:scaleType="centerCrop"
                    android:adjustViewBounds="true"
                    android:src="@drawable/more_button"/>
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/person_list_recyclerview"
                android:layout_width="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_height="wrap_content">
            </android.support.v7.widget.RecyclerView>

            <com.ct.listrtrial.Custom.CustomTextViewMedium
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/venue_detail"
                android:textSize="25sp"
                android:layout_marginLeft="10dp"
                android:textColor="@color/White"
                android:layout_marginTop="10dp"
                />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="10dp">
            <ImageView
                android:id="@+id/clock_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/clock_1"
                android:scaleType="centerCrop"
                android:paddingStart="10dp"
                />
                <com.ct.listrtrial.Custom.CustomTextViewMedium
                    android:id="@+id/opening_hours_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/opening_hours_text"
                    android:textColor="@color/White"
                    android:textSize="18sp"
                    android:paddingTop="5dp"
                    android:paddingStart="15dp"
                    android:paddingEnd="15dp"
                    />
            </LinearLayout>



        </LinearLayout>

    </LinearLayout>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/ic_share_black_24dp"
        app:layout_anchor="@id/detail_page_viewpager"
        app:layout_anchorGravity="bottom|right|end"/>

</android.support.design.widget.CoordinatorLayout>
    </RelativeLayout>
</android.support.v4.widget.NestedScrollView>

Upvotes: 0

Views: 36

Answers (1)

GuruCharan
GuruCharan

Reputation: 139

Make Your Layout Similar To Following

<FrameLayout>


    <ScrollView>

        <RelativeLayout>

            <ImageView>

            <fab1>

        </RelativeLayout>

    </ScrollView>

    <fab2>

</FrameLayout>

Make A FrameLayout As Root , Place the Fab1 will be on top of ImageView and Fab2 Top oF ScrollView

So the Fab1 Will be Fixed On Imageview and Scrollable And The Fab2 Will not be Scrollable

Hope it Helps

Upvotes: -1

Related Questions