推荐一个可扩展布局 ExpansionPanel

推荐一个可扩展布局 ExpansionPanel_第1张图片

github

引用

dependencies {点击打开链接
    compile 'com.github.florent37:expansionpanel:1.1.1'
}

使用



    

        

        ...
        
        


    

    

        

    

header

1. 与他的扩展布局连接:expansion_layout(它们必须具有相同的父布局)

2. 用expansion_headerIndicator(一个view里面header的ID)定义指示view

3. 如果要在头文件被单击时展开/关闭,请设置expansion_toggleOnClick

4. 可以用expansion_headerIndicatorRotationExpanded和expansion_headerIndicatorRotationCollapsed来修改指针旋转。

Layout

1. 可以用“app:expansion_expanded="false”修改标签的默认扩展名

2. 布局可以用.toggle()编辑

3. 使用.setEnable(true/false)启用/禁用扩展

Listener

只需将listener添加到ExpansionLayout中(不是头)获取expansion layout的状态

ExpansionLayout expansionLayout = findViewById(...);
expansionLayout.addListener(new ExpansionLayout.Listener() {
    @Override
    public void onExpansionChanged(ExpansionLayout expansionLayout, boolean expanded) {

    }
});

只打开一个

您可以设置多个扩展布局同时只打开1个

final ExpansionLayoutCollection expansionLayoutCollection = new ExpansionLayoutCollection();
expansionLayoutCollection.add(ex1);
expansionLayoutCollection.add(ex2);

expansionLayoutCollection.openOnlyOne(true);

或直接在XML中使用

  • ExpansionsViewGroupLinearLayout
  • ExpansionsViewGroupFrameLayout
  • ExpansionsViewGroupRelativeLayout
  • ExpansionsViewGroupConstraintLayout


                

Horizontal

用HorizontalExpansionLayout 代替 ExpansionLayout



        

RecyclerView

实例:

https://github.com/florent37/ExpansionPanel/blob/master/app/src/main/java/florent37/github/com/expansionpanel/SampleActivityRecycler.java

public class MyRecyclerAdapter extends RecyclerView.Adapter {

    ...

    //add an ExpansionLayoutCollection to your recycler adapter
    private final ExpansionLayoutCollection expansionsCollection = new ExpansionLayoutCollection();


    @Override
    public void onBindViewHolder(MyRecyclerHolder holder, int position) {
        //bind your elements

        //just add the ExpansionLayout (with findViewById) to the expansionsCollection
        expansionsCollection.add(holder.getExpansionLayout());
    }
}



你可能感兴趣的:(android开发)