我的页面中有一个滚动视图,其中包含一个线性布局。我的要求是在滚动此布局时添加一个浮动按钮并在此按钮单击时执行操作。如何才能做到这一点。请帮帮我。提前致谢。
问问题
3760 次
2 回答
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>
于 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 回答