Fragment加入页面切换动画——FragmentCustomAnimationSupport
来源:互联网 发布:淘宝天机平台wifi 编辑:程序博客网 时间:2024/06/05 05:22
public class FragmentCustomAnimationSupport extends FragmentActivity { int mStackLevel = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_stack); // Watch for button clicks. Button button = (Button) findViewById(R.id.new_fragment); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { addFragmentToStack(); } }); if (savedInstanceState == null) { // Do first time initialization -- add initial fragment. Fragment newFragment = CountingFragment.newInstance(mStackLevel); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.simple_fragment, newFragment).commit(); } else { mStackLevel = savedInstanceState.getInt("level"); } } //当页面销毁时存储状态字段 @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("level", mStackLevel); } void addFragmentToStack() { mStackLevel++; // Instantiate a new fragment. Fragment newFragment = CountingFragment.newInstance(mStackLevel); // Add the fragment to the activity, pushing this transaction // on to the back stack. FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); //添加了fragment之前切换动画 ft.setCustomAnimations(R.anim.fragment_slide_left_enter, R.anim.fragment_slide_left_exit, R.anim.fragment_slide_right_enter, R.anim.fragment_slide_right_exit); ft.replace(R.id.simple_fragment, newFragment); ft.addToBackStack(null); ft.commit(); } public static class CountingFragment extends Fragment { int mNum; /** * Create a new instance of CountingFragment, providing "num" * as an argument. */ static CountingFragment newInstance(int num) { CountingFragment f = new CountingFragment(); // Supply num input as an argument. Bundle args = new Bundle(); args.putInt("num", num); f.setArguments(args); return f; } /** * When creating, retrieve this instance's number from its arguments. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mNum = getArguments() != null ? getArguments().getInt("num") : 1; } /** * The Fragment's UI is just a simple text view showing its * instance number. */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.hello_world, container, false); View tv = v.findViewById(R.id.text); ((TextView) tv).setText("Fragment #" + mNum); tv.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.gallery_thumb)); return v; } }}
</pre><pre code_snippet_id="1618044" snippet_file_name="blog_20160321_3_4316788" name="code" class="java">xml:
<pre name="code" class="html"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" android:padding="4dip"> <FrameLayout android:id="@+id/simple_fragment" android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1"></FrameLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0" android:orientation="horizontal"> <Button android:id="@+id/home" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/home"> <requestFocus /> </Button> <Button android:id="@+id/new_fragment" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/new_fragment"></Button> <Button android:id="@+id/delete_fragment" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/delete_fragment"></Button> </LinearLayout></LinearLayout>
图片:
0 0
- Fragment加入页面切换动画——FragmentCustomAnimationSupport
- 使用 SharedElement 动画切换 Fragment 页面
- Fragment切换动画
- Fragment切换动画
- Android Fragment切换动画
- activity、fragment切换动画
- Fragment切换动画
- Android基础——Fragment控制切换多个页面
- Android之——Fragment控制切换多个页面
- ionic——页面切换(相当于Android中的Fragment)
- 页面切换之Fragment
- Fragment页面的切换
- 给Activity切换加入动画
- 监听Fragment的切换动画
- Fragment,Activity切换动画--Demo
- activity与fragment切换动画
- Android Fragment切换动画效果
- Activity与Fragment切换动画
- 如何正确配置 Nginx+PHP
- 肝脏的作用
- Building REST service with Scala
- eclipse修改@author的默认值
- hdu2577 How to Type---DP
- Fragment加入页面切换动画——FragmentCustomAnimationSupport
- 安装oracle遇到的bug及解决方法
- 2016年第七届蓝桥杯C/C++程序设计本科B组省赛 生日蜡烛(结果填空)
- 使用SQL语句优化优化数据库性能
- HtmlParser基础教程
- jquery跳转
- CentOS 7.0 服务管理 – systemctl 命令
- 对话框
- python学习--之dict