Android中Fragment好用的的框架

在Android中使用Fragment的需求如下

1. 以注解的形式绑定Container,也可以代码方式来实现。

支持Activity和Fragment的Container,可以一次性将多个fragment加入一个Container
同一个页面加两个fragment容器,不同容器间切换互不影响, 每个容器对应多个fragment集,两个集之间互不影响。

//åspeecific containers of Activity, It means you can show multi set of fragment in different container
@MetaphorRes(containerViewIDs = {R.id.container_number_one, R.id.container_number_two})
public class MainActivity extends AppCompatActivity {
    ......

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //get or create metaphor manager
        IMetaphorManager metaphorManager = Metaphor.with(this);

        //add a set of fragment to specify serial number container (R.id.container_number_two),and show fragment who name is m_fx1
        metaphorManager.addFragment(m_fx1, m_fx2, m_fx3).showFragment(m_fx1);
    }
}

2. 多个fragment之间更方便的:快递切换、传递消息,在任何一个子Fragment中可以随时跳转到另一个Fragment.

    //you can call getManager to get MetaphorManager in subfragment
    IMetaphorSubFragmentManager metaphorSubFragmentManager = Metaphor.getManager(this);

    //send message to base object
    metaphorSubFragmentManager.sendMessageToBase(0,null);
    //you can show fragment with tag name anywhere
    metaphorManager.showFragment("FA");

3. 在一个子的Fragment中切换另一个同级的Fragment

    //you can call getManager to get MetaphorManager in subfragment
    IMetaphorSubFragmentManager metaphorSubFragmentManager = Metaphor.getManager(this);

    //you can show fragment with tag name anywhere 
    metaphorSubFragmentManager.showFragment("FA");

推荐框架
https://github.com/xuanwenchao/Metaphor

你可能感兴趣的:(android,java,开发语言)