你的位置:首页 > 操作系统

[操作系统]伴随ListView、RecyclerView、ScrollView滚动滑入滑出小图标


 

FloatingActionButton在github上的项目主页是:https://github.com/makovkastar/FloatingActionButton

(导包的时候注意要把android-support-v7-appcompat作为它的一个Library,不要重复了NineOldAndroids的引用)

 

测试代码:

activity_main.

 1 <RelativeLayout ="http://schemas.android.com/apk/res/android" 2   ="http://schemas.android.com/tools" 3   ="http://schemas.android.com/apk/res-auto" 4   android:layout_width="match_parent" 5   android:layout_height="match_parent" 6   tools:context="com.zzw.testfloatingactionbutton.MainActivity" > 7  8   <ListView 9     android:id="@+id/listView"10     android:layout_width="match_parent"11     android:layout_height="match_parent" />12 13   <com.melnykov.fab.FloatingActionButton14     android:id="@+id/fab"15     android:layout_width="wrap_content"16     android:layout_height="wrap_content"17     android:layout_alignParentBottom="true"18     android:layout_alignParentRight="true"19     android:layout_margin="16dip"20     android:src="@drawable/ic_launcher"21     fab:fab_shadow="true"22     fab:fab_type="normal" />23 24 </RelativeLayout>

MainActivity.java:

 1 package com.zzw.testfloatingactionbutton; 2  3 import com.melnykov.fab.FloatingActionButton; 4  5 import android.app.Activity; 6 import android.os.Bundle; 7 import android.view.View; 8 import android.view.View.OnClickListener; 9 import android.widget.ArrayAdapter;10 import android.widget.ListView;11 import android.widget.Toast;12 13 14 public class MainActivity extends Activity {15 16   @Override17   protected void onCreate(Bundle savedInstanceState) {18     super.onCreate(savedInstanceState);19     setContentView(R.layout.activity_main);20     21     String[] data=new String[100]; 22     for(int i=0;i<data.length;i++){ 23       data[i]="ZZW1994"+i; 24     } 25      26     ListView listView=(ListView) findViewById(R.id.listView); 27      28     ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,data); 29     listView.setAdapter(adapter); 30      31     //附着在ListView,跟随ListView滚动滑入滑出 32     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 33     fab.attachToListView(listView); 34     fab.setColorPressed(0xffb71c1c); 35     36     37     fab.setOnClickListener(new OnClickListener() {38       39       @Override40       public void onClick(View v) {41         Toast.makeText(getApplicationContext(), "hello", 0).show();42         43       }44     });45   }46 47 }