• Android连载7-动语添加碎片


    一、

    1.我们设置主活动的框架,把主活动的屏幕分成两个碎片,各显示子活动的界面​。

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

    二、动态添加碎片

    <?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;
    
      }
    
    ​
    
    }

    二、源码:

    1.项目地址

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

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

    3.博客园:https://www.cnblogs.com/ruigege0000/

    4.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料

     

  • 相关阅读:
    设计师必备:来自顶级设计师的建议清单
    Qt 控制线程的顺序执行(使用QWaitCondition,并且线程类的run函数里记得加exec(),使得线程常驻)
    Qt 模拟鼠标点击(QApplication::sendEvent(ui->pushbutton, &event0);)
    利用Qt开发跨平台APP(二)(iOS,使用Qt5.9,很详细,有截图)
    C# RESTful API
    NET架构
    一个宏实现
    初步了解 Netty
    使用Rabbit MQ消息队列
    NET CORE与Spring Boot
  • 原文地址:https://www.cnblogs.com/ruigege0000/p/12764833.html
Copyright © 2020-2023  润新知