实现思维:

1.需要写2个或者多个子布局

2.写一个Java的class去实现将子布局与父类布局铺满。(一个子布局对应一个class)

3.在父类布局中导入fragment布局,并且添加android:name=“”属性;

1.写2个布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent">
<TextView
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下面的布局"
android:textSize="30sp"
android:textColor="@color/colorBlack"
android:maxEms="1"
android:maxLines="5"
android:layout_gravity="center"
/> </LinearLayout>
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="上面的布局"
android:textSize="30sp"
android:textColor="@color/colorBlack"
android:maxEms="1"
android:maxLines="5"/>
</LinearLayout>
 

2.Java的class去实现将子布局与父类布局铺满

package com.example.lenovo.mydebrisdemo;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by lenovo on 2018/5/5.
*/ public class Top extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.top_fragment,container,false);
return view;
}
}
 
package com.example.lenovo.mydebrisdemo;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by lenovo on 2018/5/5.
*/ public class Button extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.botton_fragment,container,false);
return view;
}
}

3.父类布局中导入fragment布局,并且添加android:name=“”属性;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--id一定要加否则会报错-->
<fragment
android:id="@+id/top"
android:name="com.example.lenovo.mydebrisdemo.Top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<fragment
android:id="@+id/button"
android:name="com.example.lenovo.mydebrisdemo.Button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/> </LinearLayout>

运行效果:

android开发 静态碎片布局实现的更多相关文章

  1. Android开发-之五大布局

    在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...

  2. Android开发5大布局方式详解

    Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...

  3. Android开发 静态static类与static方法持有Context是否导致内存泄露的疑问

    简述 在Android开发的过程中,难免会使用单例模式或者静态方法工具类.我们会让它们持有一些外部的Context或者View一般有以下几种情况: 单例模式,类的全局变量持有Context 或 Vie ...

  4. .Net程序猿玩转Android开发---(6)线性布局LinearLayout

                                LinearLayout控件是Android中重要的布局控件,是一个线性控件,所谓线性控件的意思是指该控件里面的内容仅仅能水平或垂直排列.也就 ...

  5. Android开发 ---Fragment片段布局

    前言 Fragment想必大家不陌生吧,在日常开发中,对于Fragment的使用也很频繁,现在主流的APP中,基本的架构也都是一个主页,然后每个Tab项用Fragment做布局,不同选项做切换,使用起 ...

  6. android 开发 使用自定义布局实现标题栏复用(标题栏内容自定义:使用代码实现和xml布局自定义属性2种办法实现)

    在个人学习的情况下可能很少使用自定义布局去实现大量复用的情况下,但是在一个开发工作的环境下就会使用到大量复用的自定义控件. 实现思维: 1.写一个xml的布局,用于标题栏的样式,并且添加在标题栏中你想 ...

  7. android开发学习---layout布局、显示单位和如何进行单元测试

    一.五大布局(layout) android中的用五大布局:LinearLayout (线性布局).AbsoluteLayout(绝对布局).RelativeLayout(相对布局).TableLay ...

  8. android开发中常见布局的注意点

    常见布局的注意点 线性布局: 必须有一个布局方向 水平或者垂直 在垂直布局中 只有左对齐 右对齐 水平居中生效 在水平布局中 只有顶部对齐 底部对齐 垂直居中生效 权重:组件按比例分配屏幕的剩余部分( ...

  9. Android开发中XML布局的常用属性说明

    <!-- 常用属性说明: android:id="@+id/button" 为控件指定Id android:text="NNNNNNNNNN" 指定控件的 ...

随机推荐

  1. Asp.Net Grieview Eval 绑定数据 调用JS事件

    <asp:TemplateField ItemStyle-HorizontalAlign="Center"> <ItemTemplate> <asp: ...

  2. 运行Spark提供的计算圆周率的示例程序

    1.启动Spark服务 因为spark是依赖于hadoop提供的分布式文件系统的,所以在启动spark之前,先确保hadoop在正常运行. 在hadoop正常运行的情况下,在master(也就是had ...

  3. Linux内核移植到JZ2440

    一.准备工作:1.Linux内核:Linux2.6.22.6,可从www.kernel.org上下载:2.交叉工具编译链:arm-linux-gcc-3.4.5-glibc-2.3.6:3.yaffs ...

  4. ecstore-安装提示flock,即使绕过检测,安装成功后还是提示t function 解决办法

    安装时先绕过去 安装好后,修改config.php里的TMP_DIR,指向网站目录下的data目录(用绝对路径) 分析:应该是php的运行用户没有对tmp目录的写权限.中电云集的管理工具就出现过

  5. ML: 聚类算法R包-对比

    测试验证环境 数据: 7w+ 条,数据结构如下图: > head(car.train) DV DC RV RC SOC HV LV HT LT Type TypeName 1 379 85.09 ...

  6. .net4.0、.net4.5、.net4.6 三者对系统的要求

    net4.0 支持的操作系统 Windows 7, Windows 7 Service Pack 1, Windows Server 2003 Service Pack 2, Windows Serv ...

  7. WPF Demo18 路由事件

    using System.Windows; namespace 路由事件2 { public class Student { ////声明并定义路由事件 //public static readonl ...

  8. 在 vmware player中安装 ubuntu 17.10

    目录 在 vmware 中安装 ubuntu 17.10 分区参考 vmware安装助手 第一步:更新 安装vmware tools 调整显示 第二步.输入法 五笔输入法 搜狗拼音输入法 ibus不能 ...

  9. ADO.NET目录汇总1

    1.引用命名空间: using System.Data; using System.Data.SqlClient;[访问SQL Server定义的类] 2.连接字符串 string connectio ...

  10. sql中的STRFTIME

    STRFTIME返回的是一个字符串 STRFTIME('%w',myTime) in ('1','2','4','5') 可以正确执行,而 STRFTIME('%w',myTime) in (1,2, ...