14 Fragment的V4包的使用
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/rl_fragment_id"
tools:context=".MainActivity" > </RelativeLayout>
layout.xml一个fragment的填充布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00f"
android:orientation="vertical" > </LinearLayout>
MainActivity.java
package com.qf.day14_fragment_demo08_v4; import com.qf.day14_fragment_demo08_v4.fragment.MyFragment; import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu; /**
* 1,创建一个类 继承V4包的Fragment
* 2,修改Activity 变成FragmentActivity
* 3,获取管理者对象 V4 getSupportFragmentManager() 获取事务 V4
* @author sxy
*
*/
public class MainActivity extends FragmentActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //获取Fragment的管理者
FragmentManager manager = getSupportFragmentManager();
//事务
FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.rl_fragment_id, new MyFragment()); transaction.commit();
} }
fragment对象:
package com.qf.day14_fragment_demo08_v4.fragment; import com.qf.day14_fragment_demo08_v4.R; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; public class MyFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.layout, container, false);
return view;
} }
14 Fragment的V4包的使用的更多相关文章
- app包中的fragment和v4包中的fragment的使用的区别
app包中的fragment和v4包中的fragment的使用的区别 1.尽量不要用app包中的fragment,因为这个是在3.0之后才有的,支持的版本太高,在低版本中是是用不了的 2.androi ...
- ViewPager和Fragment组合 v4包下的页面切换
/* *主页面下 */ //-------------主页面下---------------------- package com.example.viewpagerfragment; import ...
- Fragment用app包还是v4包解析
转自:http://blog.csdn.net/zc0908/article/details/50721553 1)问题简述 相信很多的朋友在调用Fragment都会遇到下面的情况: 这个时候问题来了 ...
- Android做法说明(3)---Fragment使用app袋或v4包解析
Android做法说明(3)---Fragment使用app袋或v4包解析 1)问题简述 相信非常多的朋友在调用Fragment都会遇到以下的情况: watermark/2/text/aHR0cDov ...
- 关于v4包的Fragment过渡动画的事件监听无响应问题解决
项目中部分功能模块采用了单Activity+多Fragment模式,当Fragment切换时,需要在过渡动画执行完后做一些操作,通常就是在自己封装的FragmentBase中重写onCreateAni ...
- 14 Fragment 碎片总结
Fragment 碎片 一, Fragment是什么? Android 3.0以后出现的 Api11 以上 Activity的组成部分 Fragment(小的Activity) Fragment可以显 ...
- Android 最新 Support V4 包大拆分有用吗?
Google 更新了最新的 Support Library 版本,其中最为显眼的功能莫过于 support-v4 大拆分,然后这个拆分现在看来并没有那么美好. v4 包从 2011 年开始引入,包含 ...
- 关于app.FragmentManager和v4包的FragmentPagerAdapter冲突
这几天发现一个问题我用getFragmentManager()得到FragmentManager不能放到FragmentPagerAdapter里面去.由于FragmentPagerAdapter里面 ...
- Android v4 包和v7包问题
昨天新建了一个android项目,加入了一个bootstrap的外部依赖和一个底部导航栏的外部依赖.结果jj 了,老是提醒我v4包v7包冲突: 事实是这样的,首先我的底部导航依赖库里面有一个v4包,那 ...
随机推荐
- [UOJ] #217. 【UNR #1】奇怪的线段树
题解见大佬博客 我的丑陋代码: #include<cstdio> #include<cstring> #include<cstdlib> inline int re ...
- ●洛谷P2664 树上游戏
题链: https://www.luogu.org/problemnew/show/P2664题解: 扫描线,线段树维护区间覆盖 https://www.luogu.org/blog/ZJ75211/ ...
- 【HDU 1576】 A/B
Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1). Input 数据的 ...
- FZU 2157 树形DP
最开始一直不理解题是什么意思 ╯▽╰ 题意:给出n个点,每个点都有两种花费,一个是0种花费,一个是1种花费,每两个点相连,边也有花费,是随着点所取话费的种类不同,边的花费也不同,边有四种花费,00,0 ...
- FFT模板(BZOJ2179)
实现了两个长度为n的大数相乘. #include <cstdio> #include <cmath> #include <complex> using namesp ...
- 软件测试人员在工作中如何运用Linux
从事过软件测试的小伙们就会明白会使用Linux是多么重要的一件事,工作时需要用到,面试时会被问到,简历中需要写到. 对于软件测试人员来说,不需要你多么熟练使用Linux所有命令,也不需要你对Linux ...
- Python【第一课】 Python简介和基础
本节内容 Python安装(windows) 第一个程序(windows中的python) 变量 字符编码 注释 用户输入 模块初步认识 数据类型 数据运算 表达式if...else 表达式for l ...
- face-alignment:用 pytorch 实现的 2D 和 3D 人脸对齐库
使用世界上最准确的面对齐网络从 Python 检测面部地标,能够在2D和3D坐标中检测点. 项目地址:https://github.com/1adrianb/face-alignment 作者: 阿德 ...
- dev gridcontrol 无法编辑 解决方案
1.确认表格打开编辑 gridView1.OptionsBehavior.Editable = True 2.确认列打开编辑 gridView1.Columns("Name").O ...
- 关于一些基础的Java问题的解答(二)
6. Hashcode的作用 官方对于hashCode的解释如下: Whenever it is invoked on the same object more than once during an ...