Android連載7-動語添加碎片

1、android

1.咱們設置主活動的框架,把主活動的屏幕分紅兩個碎片,各顯示子活動的界面​。git

 

<LinearLayout 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" ><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" />

 

  <fragment

      android:id="@+id/right_fragment"

      android:name="com.example.fragmenttest.RightFragment"

      android:layout_width="0dp"

      android:layout_height="match_parent"

      android:layout_weight="1" />

 

</LinearLayout>

 

2、動態添加碎片github

 

<?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"

    android:background:"#ffff00"

    android:orientation="vertical" >

   

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"

        android:textSize="20sp"

        android:text="This is another right franment"

        /></LinearLayout>

 

 

package com.example.fragmenttest;

​

import android.view.LayoutInflater;

import android.view.ViewGroup;

import android.os.Bundle;

import android.view.View;

import android.app.Fragment;

​

public class AnotherRightFragment extends Fragment {

 

  @Override

  public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.annother_right_fragment,container,false);

    return view;

  }

​

}

 

2、源碼:微信

1.項目地址app

https://github.com/ruigege66/Android/tree/master/UIBestPractice框架

2.CSDN:https://blog.csdn.net/weixin_44630050ide

3.博客園:https://www.cnblogs.com/ruigege0000/學習

4.歡迎關注微信公衆號:傅里葉變換,我的公衆號,僅用於學習交流,後臺回覆」禮包「,獲取大數據學習資料大數據

 

相關文章
相關標籤/搜索