• 【学习笔记】Fragment


    Create a Fragment Class:继承Fragment类

    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.ViewGroup;
    
    public class ArticleFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.article_view, container, false);
        }
    

    }

    Add a Fragment to an Activity using XML
    步骤一:编写xml文件 res/layout-large/news_articles.xml

    <fragment android:name="com.example.android.fragments.HeadlinesFragment"
              android:id="@+id/headlines_fragment"
              android:layout_weight="1"
              android:layout_width="0dp"
              android:layout_height="match_parent" />
    
    <fragment android:name="com.example.android.fragments.ArticleFragment"
              android:id="@+id/article_fragment"
              android:layout_weight="2"
              android:layout_width="0dp"
              android:layout_height="match_parent" />
    

    步骤二:把xml放到Activity中

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    
    public class MainActivity extends FragmentActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.news_articles);
        }
    }
  • 相关阅读:
    平安夜前夜,我在上海沐恩堂度过
    吃匹萨的数学
    2004语录
    爱的罗曼斯
    转发: 上季度全球最佳短篇小说《最后一趟生意》
    一个人的元宵节
    超越纪念我的blog排名上升到第六位
    读《仆人》
    我的龟宝宝病了:( 谁来救救她?
    春晚
  • 原文地址:https://www.cnblogs.com/muyuetiankong/p/4448418.html
Copyright © 2020-2023  润新知