实施浮动操作 icon/button 允许转到(或聚焦或向上滚动)页面顶部

Implement floating action icon/button which allows to go (or focus or scroll up) to the top of the page

任何人都可以建议我如何实现浮动操作 icon/button 允许在单击时转到(或聚焦或向上滚动)到页面顶部吗?

在此先感谢您的帮助。

将此代码添加到您的布局文件中:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:src="@drawable/ic_my_icon"
    android:layout_margin="16dp" />

然后您可以应用 View.OnClickListener 来处理 FAB 水龙头。

FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
    public void onClick(View view) 
    {
        scrollView.fullScroll(ScrollView.FOCUS_UP); //code to scroll to the top of scrollview
    } 
});