我是靠谱客的博主 勤劳猎豹,这篇文章主要介绍Android Activity加载Fragment的一般简易方法,现在分享给大家,希望可以做个参考。

Android Activity加载Fragment的一般简易方法


首先写一个布局,布局里面以FrameLayout布局为佳,
<FrameLayout 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:id="@+id/fragment"
    tools:context="com.example.demo.MainActivity" >
</FrameLayout>


然后在上层java代码中创建Fragment进而replace上面的这个FrameLayout:

package com.example.demo;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
impo

最后

以上就是勤劳猎豹最近收集整理的关于Android Activity加载Fragment的一般简易方法的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(113)

评论列表共有 0 条评论

立即
投稿
返回
顶部