【发布时间】:2019-09-05 08:34:19
【问题描述】:
我有一个nestedscrollview,其内容类似于RelativeLayout、CardViews 和textviews。由于某些原因,我也在使用floatingactionbutton 库。所以我不能使用任何行为。我不知道我应该如何处理来自scrollview 的scrollchangelistener 来像行为一样动态地隐藏和显示工厂。
现在,当程序或输出覆盖整页意图时,工厂完全消失了。它可能在内容的背后。我无法访问工厂。我想要FloatingActionButton 而不是scrollview。或者显示和隐藏工厂也是需要的。请告诉如何实现这个概念?
关于如何在滚动时隐藏和显示 fab 有什么建议吗?
<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>
【问题讨论】: