码迷,mamicode.com
首页 > 其他好文 > 详细

FragMent 初级学习

时间:2016-04-11 23:53:40      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

 FragMent 可以用在一个Activity中也可以用在多个Activity中

我们在activity中加载FragMent的时候,首先添加一个myFragMent的类

通过onCreateView方法,加载 FragMent的布局文件

 

package com.example.flagmentdemo;


import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


@SuppressLint("NewApi")
public class MyfragMent extends Fragment{
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		//return super.onCreateView(inflater, container, savedInstanceState);
		View view= inflater.inflate(R.layout.flagment, container, false);
		TextView text=(TextView) view.findViewById(R.id.textview);
		text.setText("我是静态加载的");
		return view;
	}

}

 

然后在新建的activity中加载fragment

 

在新的activity的布局文件main2中加一个fragment

  
   <fragment 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fragment"
        android:name="com.example.flagmentdemo.MyfragMent"
        />
    

然后再activity中 setContentView(R.layout.main2)

 

FragMent 初级学习

标签:

原文地址:http://www.cnblogs.com/XingzhiDai/p/5380505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!