2012-07-19 88 views
2

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

回答

4

也许我误解了你的问题,但它听起来像你想要一个固定的Button以外的ScrollView,以便您可以滚动并始终看到Button

如果是这样,只需添加Button OUTSIDE的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> 
+0

在按钮和滚动视图之外,可以使用一个relativelayout进行换行。并且Button可以与android:layout_alignParentBottom =“true”,android:layout_alignParentRight =“true”一起使用以对齐到父母的右下位置。 – juejiang 2015-09-29 02:28:30

3

使用this library,它已经做过的事情。

包括在您的项目:

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)); 

这一切,它应该工作!

查看我的original post here并查看example app

相关问题