2

我的页面中有一个滚动视图,其中包含一个线性布局。我的要求是在滚动此布局时添加一个浮动按钮并在此按钮单击时执行操作。如何才能做到这一点。请帮帮我。提前致谢。

4

2 回答 2

4

也许我误解了你的问题,但听起来你想要一个固定Button在你之外的东西,ScrollView这样你就可以滚动并总是看到Button?

如果是这样,只需添加ButtonOUTSIDE ScrollView

<Button
    android:id="@+id/button_save"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Save" />

<ScrollView
    android:id="@+id/scrollView_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </LinearLayout>
</ScrollView>
于 2012-07-26T01:09:27.717 回答
3

使用这个库,它已经完成了你需要的事情。

将其包含在您的项目中:

dependencies {
    compile 'com.shamanland:fab:0.0.5'
}

添加FloatingActionButton到您的布局而不是常规Button

<com.shamanland.fab.FloatingActionButton
    android:id="@+id/button_save"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

将其与ScrollView

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.button_save);
ScrollView scrollView = (ListView) findViewById(R.id.scrollView_list);
scrollView.setOnTouchListener(new ShowHideOnScroll(fab));

就是这样,它应该工作!

在此处查看我的原始帖子并查看示例应用程序

于 2014-09-09T07:43:34.917 回答