浮动动作按钮在scrollview android中滚动时隐藏并显示?

时间:2019-09-05 08:34:19

标签: java android xml

我有一个nestedscrollview,其内容类似于某些RelativeLayoutCardViewstextviews。我出于某些原因也正在使用floatingactionbutton库。所以我不能使用任何行为。我不知道应该如何处理scrollchangelistener中的scrollview来像行为一样动态隐藏和显示工厂。 现在,当程序或输出覆盖整个意图页面时,晶圆厂完全消失了。它可能在内容后面。我无法访问工厂。我希望FloatingActionButton上的scrollview。或显示和隐藏晶圆厂也是需要的。请告诉我如何实现这个概念?

关于滚动时如何隐藏和显示晶圆厂的任何建议?

<ScrollView 
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:scrollbars="none"
android:background="#fff"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">


<RelativeLayout
    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"
    tools:context=".programs.PrintANumber">

    <android.support.v7.widget.CardView
        android:id="@+id/program_title_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        app:cardElevation="2dp"
        android:layout_below="@id/definition_content"
        android:layout_centerHorizontal="true"
        app:contentPadding="15dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Print a Number"
            android:textColor="@color/colorPrimaryDark"
            android:textAlignment="center"
            android:textSize="20sp"
            android:textStyle="bold"/>
    </android.support.v7.widget.CardView>


    <android.support.v7.widget.CardView
        android:id="@+id/sourcecode_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        app:cardElevation="2dp"
        android:layout_below="@id/program_title_card"
        android:layout_centerHorizontal="true"
        app:contentPadding="6dp">

        <thereisnospon.codeview.CodeView
            android:id="@+id/program"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </thereisnospon.codeview.CodeView>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/output_title_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        app:cardElevation="2dp"
        android:layout_below="@id/sourcecode_card"
        android:layout_centerHorizontal="true"
        app:contentPadding="15dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Output"
            android:textColor="@color/colorPrimaryDark"
            android:textAlignment="center"
            android:textSize="20sp"
            android:textStyle="bold"/>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/output_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        app:cardElevation="2dp"
        android:layout_below="@id/output_title_card"
        android:layout_centerHorizontal="true"
        app:contentPadding="6dp">

        <thereisnospon.codeview.CodeView
            android:id="@+id/output"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </thereisnospon.codeview.CodeView>
    </android.support.v7.widget.CardView>

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom|end"
        android:paddingRight="10dp"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        fab:menu_labels_ellipsize="end"
        fab:menu_labels_singleLine="true"
        app:menu_icon="@drawable/fab_add"
        fab:menu_backgroundColor="#ccffffff"
        app:menu_colorNormal="@color/lightGrey"
        android:elevation="2dp">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/id_opt1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/opt1"
            android:padding="5dp"
            fab:fab_size="mini"
            fab:fab_label="Option1"
            app:rippleColor="@color/colorAccent"
            app:fab_colorNormal="@color/colorAccent" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/id_opt2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/opt2"
            android:padding="5dp"
            fab:fab_size="mini"
            fab:fab_label="Option2"
            app:rippleColor="@color/colorAccent"
            app:fab_colorNormal="@color/colorAccent" />

    </com.github.clans.fab.FloatingActionMenu>

</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

您正在滚动视图标记内使用“浮动”操作。将其移出滚动视图。

使用类似这样的内容:

<RelativeLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/apk/res-auto">

<com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom|end"
        android:paddingRight="10dp"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        fab:menu_labels_ellipsize="end"
        fab:menu_labels_singleLine="true"
        app:menu_icon="@drawable/fab_add"
        fab:menu_backgroundColor="#ccffffff"
        app:menu_colorNormal="@color/lightGrey"
        android:elevation="2dp">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/id_opt1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/opt1"
            android:padding="5dp"
            fab:fab_size="mini"
            fab:fab_label="Option1"
            app:rippleColor="@color/colorAccent"
            app:fab_colorNormal="@color/colorAccent" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/id_opt2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/opt2"
            android:padding="5dp"
            fab:fab_size="mini"
            fab:fab_label="Option2"
            app:rippleColor="@color/colorAccent"
            app:fab_colorNormal="@color/colorAccent" />

    </com.github.clans.fab.FloatingActionMenu>
<ScrollView 
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:scrollbars="none"
        android:background="#fff"
        android:fillViewport="true"
        xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout
            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"
            tools:context=".programs.PrintANumber">

    <android.support.v7.widget.CardView
        android:id="@+id/program_title_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        app:cardElevation="2dp"
        android:layout_below="@id/definition_content"
        android:layout_centerHorizontal="true"
        app:contentPadding="15dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Print a Number"
            android:textColor="@color/colorPrimaryDark"
            android:textAlignment="center"
            android:textSize="20sp"
            android:textStyle="bold"/>
    </android.support.v7.widget.CardView>


    <android.support.v7.widget.CardView
        android:id="@+id/sourcecode_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        app:cardElevation="2dp"
        android:layout_below="@id/program_title_card"
        android:layout_centerHorizontal="true"
        app:contentPadding="6dp">

        <thereisnospon.codeview.CodeView
            android:id="@+id/program"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </thereisnospon.codeview.CodeView>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/output_title_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        app:cardElevation="2dp"
        android:layout_below="@id/sourcecode_card"
        android:layout_centerHorizontal="true"
        app:contentPadding="15dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Output"
            android:textColor="@color/colorPrimaryDark"
            android:textAlignment="center"
            android:textSize="20sp"
            android:textStyle="bold"/>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/output_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="6dp"
        app:cardElevation="2dp"
        android:layout_below="@id/output_title_card"
        android:layout_centerHorizontal="true"
        app:contentPadding="6dp">

        <thereisnospon.codeview.CodeView
            android:id="@+id/output"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </thereisnospon.codeview.CodeView>
    </android.support.v7.widget.CardView>

</RelativeLayout>
</ScrollView>
</RelativeLayout>

答案 1 :(得分:0)

尝试这样。

b
相关问题