Android中碎片的添加问题
碎片在Android中的应用是十分广泛的,它就像是嵌在活动中的另一个活动就像是一个容器包含了另一个容器,那么到底该怎么添加碎片呢?主要有两种方法,一种是在该碎片所在的xml文档中使用Android:name属性来添加动态加载碎片布局的类的类名(包括完整的包名),动态加载碎片布局用的就是layoutinflater类中的inflate方法,
package com.example.asus.fragmenttest; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by ASUS on 2019/2/23.
*/ public class AnotherRightFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.another_right_fragment,container,false);
return view;
}
}
而碎片实质上和活动一样,它也有xml布局文档等等之类的活动有的东西。
<?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:orientation="vertical"
android:background="#ffff00">
<TextView
android:text="This is another right fragment"
android:layout_gravity="center_horizontal"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
碎片只是放在了<frgment>控件中,但是它五脏俱全
如果不把碎片放在<frgment>控件中,那么可以再活动的.java文件中用replacefragment方法进行动态的加载,只需传入动态加载碎片布局的类的对象参数。
Android中碎片的添加问题的更多相关文章
- Android中如何动态添加碎片
Android中的开发需要兼容手机和平板,两个方面.这就引入了碎片的概念.(注意:这里用的Fragment强烈建议使用support-v4库中的Fragment) 碎片:是一种可以嵌入在活动当中的UI ...
- android中添加只有border-left的样式
如何在android中的边框添加只有左边边框有颜色的样式呢 1. 相应的drawable文件 <?xml version="1.0" encoding="utf-8 ...
- Android中WebView的JavaScript代码和本地代码交互的三种方式
一.Android中WebView的漏洞分析最近在开发过程中遇到一个问题,就是WebView使用的时候,还是需要解决之前系统(4.2之前)导致的一个漏洞,虽然现在这个系统版本用户很少了,但是也不能忽视 ...
- android中添加背景音乐
方法一:这是使用java中的多线程,另外new出一个类,用类来启动音乐. 这个方法,就像当初写java的小游戏一样,不过是在电脑上运行的,可以控制每一个动作,比如你的触碰动作,但是,在我这个游戏中,我 ...
- Android中添加自己的模块 【转】
本文转载自:http://wallage.blog.163.com/blog/static/17389624201021791333695/ 转:http://blog.csdn.net/yili_x ...
- Android studio中为项目添加模块依赖的过程
https://blog.csdn.net/cheng__lu/article/details/74574582 Android studio中为项目添加模块依赖的过程 1.点击菜单file>p ...
- Android中添加监听回调接口的方法
在Android中,我们经常会添加一些监听回调的接口供别的类来回调,比如自定义一个PopupWindow,需要让new这个PopupWindow的Activity来监听PopupWindow中的一些组 ...
- Android中ActionBar和ToolBar添加返回箭头
感谢大佬:https://blog.csdn.net/baidu_32682229/article/details/77927745 ActionBar添加返回箭头 //onCreate方法中 Act ...
- Android中Fragment与Activity之间的交互(两种实现方式)
(未给Fragment的布局设置BackGound) 之前关于Android中Fragment的概念以及创建方式,我专门写了一篇博文<Android中Fragment的两种创建方式>,就如 ...
随机推荐
- 异想-天开 python---while、for、if-else 循环学习
for循环: for i in range(10): # i循环10次 print('------',i) for j in range(10): print(j) if j > 2 : bre ...
- 【转】tars源码漫谈第1篇------tc_loki.h (牛逼哄哄的loki库)
loki库是C++模板大牛Andrei写的, 里面大量运用模板的特性, 而tc_loki.h借用了loki库的部分代码, 形成了一个基本的文件tc_loki.h, 来看看: #ifndef __TC_ ...
- 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165317
第一周作业 Kali的安装 Kali的下载 从kali官网下载kali-linux 64-bit 版本. Kali的安装 由于在娄老师的课上使用virtualbox, 所以我习惯性使用virtual ...
- 爬虫-----selenium模块自动爬取网页资源
selenium介绍与使用 1 selenium介绍 什么是selenium?selenium是Python的一个第三方库,对外提供的接口可以操作浏览器,然后让浏览器完成自动化的操作. sel ...
- python中字符串的拼接
1.+ 号 2.format() 3.f"{username}登录成功" 4.%s 5.列表中的 join 6.逗号 http://www.cnblogs.com/gengcx/p ...
- Asp.net 使用线程池实例
实际开发经常会使用线程,如果每次使用都是创建线程.启动线程,然后销毁线程,从性能上来讲,非常占用系统开销,当线程达到一定量的时候会影响程序的运行和处理效率. 使用线程池:好处:线程池是一种多线程处理形 ...
- 常用邮箱POP3 STMP服务器与端口号设置
一.常用邮箱POP3 STMP服务器与端口号设置: [网易 163.126免费邮箱目前不直接开放smtp.pop3服务.有需要的用户可通过购买随身邮或邮箱伴侣及加入会员中心获得.从2006年11月16 ...
- 项目从.net core 2.1.0升级到.net core 2.2.4,原有项目出错及解决方案
... 1.Controller中的形参命名为query.pager,且里面实体中的参数也有Query.Pager参数时,Query.Pager 就会无数据. 解决方案: 形参query.pager ...
- CentOS 7 扩大/root分区
Linux 根目录爆满解决 亲测有效!转载自https://blog.csdn.net/e_wsq/article/details/79531493 CentOS 7 调整 home分区扩大 root ...
- 网络库压力测试:mongols VS evpp
evpp是360出品的一个网络库,基于libevent,进行了许多改造,对c++11友好.据称比libevent性能要好. 到底有多好呢?360开发人员有自己的测试,信不信由你. evpp源码下有个h ...