简体   繁体   English

浮动动作按钮滚动错误

[英]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 我在ImageView的顶部有两个FAB(FAB:浮动操作按钮),在另一个ImageView右下角有一个FAB。

My problem is that I'm trying to make the top FAB to be fixed and the other one scrollable. 我的问题是,我正在尝试固定顶部的FAB,使另一个FAB可滚动。 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 . 我尝试从ScrollView取出一个FAB,但仍然无法正常工作,因为两个FAB最初都位于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>

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 将FrameLayout作为Root放置,将Fab1放置在ImageView和Fab2顶部ScrollView的顶部

So the Fab1 Will be Fixed On Imageview and Scrollable And The Fab2 Will not be Scrollable 因此,Fab1将固定在Imageview上并且可滚动,而Fab2将不可滚动

Hope it Helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM