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是系统自带的

  • 相关阅读:
    托管和使用WCF服务:WAS(Windows激活服务)
    突发的灵感
    C# 常见图像处理效果
    C# WinForm TreeView 递归选择父节点和子节点
    C# WinForm ComboBox 枚举 选定值
    C# Socket 异步 UDP
    C# WinForm 判断窗体控件是否修改过
    C# 线程同步 信号量 Semaphore
    C# WinForm ComboBox Items 选定值
    C# WinForm ComboBox 自定义数据项 (ComboBoxItem )
  • 原文地址:https://www.cnblogs.com/fanfusuzi/p/7017833.html
Copyright © 2011-2022 走看看