2012-07-19 89 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

相關問題