技术标签: Fragment
首先声明三点:
1、在需要嵌套Fragment的activity必须继承android.support.v4.app.FragmentActivity
2、嵌套的Fragment必须继承android.support.v4.app.Fragment
3、此教程仅适用于新手或者老手查阅
先上一个目录结构:
步骤:
1、新建一个嵌套fragment的activity:MainAcitivity.java和对应的布局文件main_activity.xml
main_activity.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical" tools:context="com.ruan.app.MainActivity"> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1"></FrameLayout> </LinearLayout>
MainAcitivity.java
package com.ruan.app; import android.support.v4.app.FragmentActivity; import android.os.Bundle; public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); //必需继承FragmentActivity,嵌套fragment只需要这行代码 getSupportFragmentManager().beginTransaction().replace(R.id.container, new MyFragment()).commitAllowingStateLoss(); } }
2、新建一个需要嵌套的Fragment:MyFragment.java和对应布局文件my_fragment.xml
my_fragment.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorAccent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textColor="#ffffff" android:textSize="48dp" android:text="myfragment"/> </RelativeLayout>
MyFragment.java
package com.ruan.app; 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) { return inflater.inflate(R.layout.my_fragment, null); } }
好,完事 运行,下面是效果图
代码下载地址:http://pan.baidu.com/s/1hr8FYLI
1.表格展示: 2.读取表格数据: private File regionFile ; public File getRegionFile() { return regionFile; } public void setRegionFile(File regionFile) { this.regionFile = regi...
如何用python实现两个文件重复数据筛选并统计如何利用python提取两个excel对比后的重复值的信息?请问: 例如我有两个Excel表格, 一个表格 Ex1 是三列,每列都有5000行, 有import pandasdef read_excel(): data1 = pandas.read_excel(r'C:\Users\admin\Desktop\1.xlsx') data2 = pan...
vue中点击菜单,更换对应的选中的图片和字体颜色我都是直接截的图,这样可以让你们边看边自己敲,这样可以更好的学习,脑过千遍不如手过一遍将菜单数组写好或者可以用后台数据(必须有选中的和未选中的图片路径,图片必须用require引入,不然无法显示)for循环到页面上,在data中声明一个变量在点击事件中传一个index下标,当点击的时候将声明的变量等于下标在渲染图片的时候通过三元运算符渲染,当点击的下标等于声明的变量值的时候展示点击选中的图片,更换字体颜色通过动态绑定class名,当点击
一 g++ 编译运行hello world1编写hello world 代码#include<iostream>using namespace std;int main(){ cout << "hello world!" << endl; return 0;}2 编译及运行自动生成了a.out可执行的文件[email protected]:~/work/cpp$ g++ h
phpcms关闭后台登陆验证码的方法如下:找到网站/phpcms/modules/admin/index.php 查找“//判断验证码”并注释//判断验证码$code=isset($_POST['code'])&&trim($_POST['code'])?trim($_POST['code']):showmessage(L('input_code'),HTTP_...
在使用spring加载jar包中的配置文件时,不支持通配符,需要一个一个引入,如下所示:Java代码 &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; classpath*:beanconfigs/applicationC...
原子操作Linux内核提供了多种同步机制,这些机制本质上都是通过原子操作来实现的。原子操作可以保证指令以原子方式执行,不会被中途打断(中断也不会打断一个指令,处理器只有在当前指令完成后才会去处理中断)。内核提供了两套原子操作的接口,一套用于整数原子操作,一套用于进行位原子操作。这些接口的实现是和架构相关的,Linux系统支持的所有架构都实现了这些接口。大部分架构为简单的算术运算提供了原子版本的...
早就想写一个有关RSS的文章,一直没时间,今天刚好被现DL说了一波,那就先整理出一篇教程吧。后续说不定还有分享: 分享相关PPT: 一、我使用的服务:Feedly:https://feedly.com/注册使用即可。一个账号可以免费订阅200个RSS源,完全足够日常需要;二、RSS可订阅的内容+获取RSS链接:注:此部分内容有点过时,因为目前所有的订阅源都可以从RSS Hub...
You can change or stay the same.There are no rules to thisthing. ——本杰明.巴顿正文官方文档https://muyangmin.github.io/glide-docs-cn/doc/download-setup.html准备工作gradle添加依赖:dependencies {...
1、频率区别FM = Frequency Modulation 调频,微波;微波传输,信号质量高,传输成本低,发射功率小,覆盖范围小,受地理因素影响较大,一般作为城市广播的首选。比如你的家乡城市台,一般可以通过FM收听。AM = Amplitude Modulation 调幅,微波;中波传输,信号质量稳定,传出成本大,发射功率大,覆盖范围广,靠天馈传输,受天气条件影响较大,一般作为远距离传...
题目:http://acm.split.hdu.edu.cn/showproblem.php?pid=5438题意:有一些带权的池塘,池塘间用管道连接,要求去掉剩下池塘中度数题解:先利用拓扑方法,利用栈,将所有度数代码:#include#include#include#include#include#includeusing namespace std;int va
Author:赵志乾Date:2020-06-05Declaration:All Right Reserved!!!踩坑:场景:业务记录需要唯一标识,也就是我们使用的业务id。做法:本地通过时间戳+业务串+随机数的规则生成业务id,当在循环中使用该方法是会产生重复的业务id。代码如下:public class ServiceIdGenerator { private static DateFormat dateFormat = new SimpleDateFormat("yy.