zoukankan      html  css  js  c++  java
  • 两个fragment之间简单的跳转

    1.在第一个fragment中开启事务,设置标记

     Toast.makeText(getActivity(), "切换到下一个fragment中", Toast.LENGTH_SHORT).show();
                    //开启事务跳转
                    FragmentTransaction transaction = getFragmentManager().beginTransaction();
                    String textItem =  ((TextView) view).getText().toString();
                    ProduceDetailFragment produceDetailFragment = new ProduceDetailFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("productTitle", textItem);
                    produceDetailFragment.setArguments(bundle);
    
                    transaction
                            .addToBackStack(null)  //将当前fragment加入到返回栈中
                            .replace(R.id.fl_main_fragment,produceDetailFragment)
                            .show(produceDetailFragment)
                            .commit();

    2.在第二个里面

     @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.activity_produce, container, false);
            ButterKnife.bind(this, view);
            //设置公共标题
             setTitle();
            initData();
    
            return view;
        }

    3.获取数据

       /*--------------设置公共标题-------------*/
        private void setTitle() {
            title = getArguments().getString("productTitle");
            tvCustomTitle.setText(title);
            btnClose.setText("返回");
            btnSearch.setVisibility(View.GONE);
    
        }

     4.返回到上一个fragment

        @OnClick(R.id.btn_close)
        public void onClick() {
           getFragmentManager().popBackStack();
        }

    5. 设置fragment的跳转动画

    transaction.setCustomAnimations(R.anim.enter,R.anim.exit,android.R.anim.slide_in_left,android.R.anim.slide_out_right);
    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:fromXDelta="100%p" android:toXDelta="0"
            android:duration="@android:integer/config_mediumAnimTime"/>
    </set>

    exit.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:fromXDelta="0" android:toXDelta="-100%p"
            android:duration="@android:integer/config_mediumAnimTime"/>
    </set>

    popexit.xml,popenter.xml是系统自带的

  • 相关阅读:
    Linux 系统的启动过程
    Oracle中row_number()、rank()、dense_rank() 的区别
    Java 动态打印菱形代码之for循环的使用
    Oracle 体系结构chapter2
    Oracle 11g 概述 chaper1
    go解决ctrl+鼠标左键或F12失效问题
    解决unrecognized import path "golang.org/x/sys/windows"问题
    设计规范
    性能分析
    用IDEA导入项目时,项目中的SpringBoot注解无法识别
  • 原文地址:https://www.cnblogs.com/fanfusuzi/p/7017833.html
Copyright © 2011-2022 走看看