Android — — —动态添加碎片
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff00"> <TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is another fragment"
android:textSize="30sp"
android:layout_gravity="center"/> </LinearLayout>
package com.example.fragmenttest; import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by Administrator on 2016/3/2.
*/
public class AnotherRightFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = inflater.inflate(R.layout.another_right_fragment,container,false);
return view;
}
}
<?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" > <fragment
android:id="@+id/left_fragment"
android:name="com.example.fragmenttest.LeftFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/> <FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/right_layout"> <fragment
android:id="@+id/right_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.fragmenttest.RightFragment"/> </FrameLayout> </LinearLayout>
package com.example.fragmenttest; import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class MainActivity extends Activity implements View.OnClickListener{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(this);
} @Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
AnotherRightFragment fragment = new AnotherRightFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.right_layout,fragment);
//模拟返回栈
//transaction.addToBackStack(null);
transaction.commit();
break;
default:
break;
} }
}
Android — — —动态添加碎片的更多相关文章
- Android动态添加碎片
我们编写一个能够用过按钮动态更替碎片的APP,首先在主页上显示第一个碎片,点击按钮后可以替换到第二个碎片,或者删除已经替换掉的第二个碎片. 一.MainActivity.java import and ...
- Android中如何动态添加碎片
Android中的开发需要兼容手机和平板,两个方面.这就引入了碎片的概念.(注意:这里用的Fragment强烈建议使用support-v4库中的Fragment) 碎片:是一种可以嵌入在活动当中的UI ...
- Android动态添加Device Admin权限
/********************************************************************** * Android动态添加Device Admin权限 ...
- Android 动态添加Spinner(.java文件内实现) 实现 改变spinner 内文字属性
动态添加spinner 控件 Spinner s = new Spinner(this); String []items={"自己定义的要显示的数组"}; my_SpinnerAd ...
- Android动态添加和移除布局
package com.hyang.administrator.studentproject; import android.os.Bundle; import android.support.v7. ...
- android动态添加TextView或者ImageView
动态添加 text1=new TextView(this); text1.setText("动态添加"); ((LinearLayout) this.findViewById(R. ...
- Android -- 动态添加布局
在做项目的时候,遇到了scrollView与listView结合的使用,导致了滑动的混乱,但是有一个办法可以解决掉这个问题,就是手写listView的高度,还有另外一种方法,传送门:<Andro ...
- Android 动态添加删除ExpandableListView的item的例子
这个例子可以学习到如下几点: 1.通过自定义Dialog(单独布局的xml文件进行弹出显示) 2.通过menu点击监听添加,删除view中的items 3.点击ExpandableListView中g ...
- Android动态添加布局
//1.利用LayoutInflater的inflate动态加载XML mLinearLayout = (LinearLayout)findViewById(R.id.LinearLayout_ID) ...
随机推荐
- jenkins添加git源码目录时报Error performing command错误
简介 这是我在构建一个自动化部署项目中遇到的一个异常 解决步骤: 1.进入的jenkins的home目录,执行下面命令生成公钥和私钥 [root@jacky .jenkins]# ssh-keygen ...
- this
JavaScript 中的 this ! 2016-12-28 vvv阿城 JavaScript 转自 https://qiutc.me/post/this-this-this-in-javascr ...
- 不在折腾---hive-0.13.1-bin
Hive只在一个节点安装即可 上传tar包 解压 > tar zxvf hive-0.13.1-bin.tar.gz 配置mysql * 检查MySQL是否安装:rpm -qa | grep m ...
- Linux下漏洞提权
Linux下的漏洞提权 linux下一般都是系统漏洞提权,分为以下几个步骤:
- [iOS]浅谈NSRunloop工作原理和相关应用
一. 认识NSRunloop 1.1 NSRunloop与程序运行 那么具体什么是NSRunLoop呢?其实NSRunLoop的本质是一个消息机制的处理模式.让我们首先来看一下程序的入口——main ...
- php时间设置为本地
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to ...
- NoSQL生态系统——类似Bigtable列存储,或者Dynamo的key存储(kv存储如BDB,结构化存储如redis,文档存储如mongoDB)
摘自:http://www.ituring.com.cn/article/4002# NoSQL系统的数据操作接口应该是非SQL类型的.但在NoSQL社区,NoSQL被赋予了更具有包容性的含义,其意为 ...
- Mac Mysql初始密码重置
今天晚上mac更新后重装MySQL 安装完成后 启动服务,死活登录不了 提示1045错误.按照网上的资料对MySQL密码进行重置.记录步骤如下: 1.首先关闭MySQL服务 系统偏好设置->最下 ...
- Android-内存泄漏
单例造成的内存泄漏 单例模式非常受开发者的喜爱,不过使用的不恰当的话也会造成内存泄漏,由于单例的静态特性使得单例的生命周期和应用的生命周期一样长,这就说明了如果一个对象已经不需要使用了,而单例对象 ...
- chattr和lsattr
这两个命令是和权限有关 1.chattr +i carlton.txt 对carlton.txt文件进行锁定,谁也不能进行任何修改,取消的话可以chattr -i carlton.txt 就可以 2. ...