【开源】Floating Action Button
Floating Action Button
- https://github.com/shamanland/floating-action-button
介绍:
浮动操作按钮,可以配合ListView等滚动控件,实现当ListView 向上滑动的时候按钮就会显示出来,当向下滑动按钮会自动隐藏。请注意这个库的FloatingActionButton是和滚动控件没有耦合的, 该库代码封装的比较好,使用起来比较简单。可以自定义动画效果。运行效果:
![]()
使用说明:
xml中:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" /> <com.shamanland.fab.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_marginRight="16dp" android:layout_marginBottom="20dp" android:src="?attr/icActionEdit" /></RelativeLayout> |
其中com.shamanland.fab.FloatingActionButton就是我们的浮动操作按钮,然后在java代码中将他和ListView关联:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
super.onCreate(state);setContentView(R.layout.a_example_list);View fab = findViewById(R.id.fab);fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(v.getContext(), R.string.action_clicked, Toast.LENGTH_SHORT).show(); }});ListView listView = (ListView) findViewById(android.R.id.list);listView.setAdapter(new ExampleAdapter());listView.setOnTouchListener(new ShowHideOnScroll(fab)); |
其中的ListView完全可以替换成其他控件。
posted on 2015-04-02 10:38 wasdchenhao 阅读(187) 评论(0) 收藏 举报

浙公网安备 33010602011771号