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

fragment介绍

时间:2019-01-11 21:15:04      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:layout   com   view   inf   override   one   undle   ret   inflate   

fragment介绍 

  • fragment总是被嵌入到Activity里 fragment要添加到ViewGroup里 
  • fragment是在android3.0的时候被引入的. 
  • 代码实现 
    • 在布局声明
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <fragment
        android:id="@+id/fragment1"
        android:name="ngyb.statementfragment.BlankFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <fragment
        android:id="@+id/fragment2"
        android:name="ngyb.statementfragment.BlankFragment2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>
    • 声明fragment 需要重写onCreateView方法 
public class BlankFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_blank, null);
    }
}

 

fragment介绍

标签:layout   com   view   inf   override   one   undle   ret   inflate   

原文地址:https://www.cnblogs.com/nangongyibin/p/10257140.html

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