水平瀑布流收缩动画_Android源码

 

##Requirements

  • Android SDK 18+

##Usage

Add to your root build.gradle:

allprojects {
	repositories {	...
	maven { url "https://jitpack.io" }
	}
}

Add the dependency:

dependencies {
	  compile 'com.github.Yalantis:SearchFilter:v1.0.4'}

How to use this library

Firstly you need to place Filter above your RecyclerView in the layout file




    

        

            

                

                

                

            

        
    

    

        

        

    

After that you need to create a class that extends FilterAdapter and to pass your model class as a generic. Here you can easily customize the appearance of filter items. For the sample app I created Tag model to represent the category of a question in the conversation.

class Adapter extends FilterAdapter {        Adapter(@NotNull List items) {            super(items);
        }        @NotNull
        @Override
        public FilterItem createView(int position, Tag item) {            FilterItem filterItem = new FilterItem(ExampleActivity.this);

            filterItem.setStrokeColor(mColors[0]);
            filterItem.setTextColor(mColors[0]);
            filterItem.setCheckedTextColor(ContextCompat.getColor(ExampleActivity.this, android.R.color.white));
            filterItem.setColor(ContextCompat.getColor(ExampleActivity.this, android.R.color.white));
            filterItem.setCheckedColor(mColors[position]);
            filterItem.setText(item.getText());
            filterItem.deselect();            return filterItem;
        }
    }

To receive all the events from the Filter such as selection or deselection of a filter item it's necessary to add a FilterListener with the same model class passed as a generic

private FilterListener mListener = new FilterListener() {        @Override
        public void onFiltersSelected(@NotNull ArrayList filters) {
            
        }        @Override
        public void onNothingSelected() {

        }        @Override
        public void onFilterSelected(Tag item) {

        }        @Override
        public void onFilterDeselected(Tag item) {

        }

    };

Basically Filter setup looks like that

 mFilter = (Filter) findViewById(R.id.filter);
 mFilter.setAdapter(new Adapter(getTags()));
 mFilter.setListener(this); //the text to show when there's no selected items
 mFilter.setNoSelectedItemText(getString(R.string.str_all_selected));
 mFilter.build();

For more usage examples please review sample app

源码下载

你可能感兴趣的:(android)