伴随ListView、RecyclerView、ScrollView滚动滑入滑出小图标--第三方开源--FloatingActionButton
2015-12-02 13:15
519 查看
FloatingActionButton在github上的项目主页是:https://github.com/makovkastar/FloatingActionButton
它的依赖包NineOldAndroids在github上的项目主页是:https://github.com/JakeWharton/NineOldAndroids
(导包的时候注意要把android-support-v7-appcompat作为它的一个Library,不要重复了NineOldAndroids的引用)
测试代码:
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:fab="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.zzw.testfloatingactionbutton.MainActivity" > <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" /> <com.melnykov.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_margin="16dip" android:src="@drawable/ic_launcher" fab:fab_shadow="true" fab:fab_type="normal" /> </RelativeLayout>
MainActivity.java:
package com.zzw.testfloatingactionbutton; import com.melnykov.fab.FloatingActionButton; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String[] data=new String[100]; for(int i=0;i<data.length;i++){ data[i]="ZZW1994"+i; } ListView listView=(ListView) findViewById(R.id.listView); ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,data); listView.setAdapter(adapter); //附着在ListView,跟随ListView滚动滑入滑出 FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.attachToListView(listView); fab.setColorPressed(0xffb71c1c); fab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "hello", 0).show(); } }); } }
相关文章推荐
- iOS音频文件拼接+裁剪(音频文件拼接做了性能优化)
- ZZULIOJ 1400 这不可能是情书吧
- jQuery选择器之基本选择器和层次选择器
- LeetCode---Ugly Number II
- NSNumber和Int的互相转换
- 使用Myeclipse内置Ant编译项目时提醒警告java\lang\Object.class(java\lang:Object.class): 主版本 51 比 50 新,此编译器支持最新的主版本
- centos编译telepresence测试效果
- 百钱买百鸡
- android--RecycleView.Adapter的初体验
- 人工智能(AI)资料大全
- LintCode: Flatten Binary Tree to Linked List
- win7下,vs2013+qt5.3+qwt6.1.2安装配置
- android透明状态栏
- Java开发环境
- NYOJ 463 九九乘法表
- 一个美国人到中国当产品经理的心得:中国App设计真好!
- Activiti学习笔记目录
- Codeforces Round #334 (Div. 2)-More Cowbell(贪心模拟)
- 【FastDev4Android框架开发】HorizontalScrollView,Fragment,FragmentStatePagerAdapter打造网易新闻Tab及滑动页面效果(三十六)
- jQuery基础