提升布局性能____Re-using Layouts with <include/>

可以再一个布局中通过“include”和“merge”元素进行复用其他的布局元素。

比如如下一个布局:

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"   
android:layout_width=”match_parent”    
android:layout_height="wrap_content"    
android:background="@color/titlebar_bg">    <ImageView 
android:layout_width="wrap_content"               
android:layout_height="wrap_content"                
android:src="@drawable/gafricalogo" />
</FrameLayout>

这是一个可复用的布局文件,倘若有以下的布局文件:

<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/app_bg"    
android:gravity="center_horizontal">    <include 
layout="@layout/titlebar"/>    <TextView 
android:layout_width=”match_parent”              
android:layout_height="wrap_content"              
android:text="@string/hello"              
android:padding="10dp" />    ...
</LinearLayout>

则包含了被复用的文件。

当然,如果在包含者当中,需要调整被包含者的属性,也可以:

<include android:id=”@+id/news_title”         
android:layout_width=”match_parent”
android:layout_height=”match_parent”
layout=”@layout/title”/>

这样就重新调整了被包含者的属性。

 

android中海油另一个“merge”标签,看了官方文档后,我个人理解是这样:

假使主布局中的根元素是线性布局,通过include包含了一个子布局,该子布局的根元素仍然是线性布局,那么包含后就与主布局的线性元素重复了,所以可以通过“merge”来解决,

<merge 
xmlns:android="http://schemas.android.com/apk/res/android">    
<Button        android:layout_width="fill_parent"         
android:layout_height="wrap_content"        
android:text="@string/add"/>    
<Button        android:layout_width="fill_parent"         
android:layout_height="wrap_content"        
android:text="@string/delete"/>
</merge>

 

 

转载于:https://www.cnblogs.com/itblog/p/7236620.html

<!DOCTYPE html> <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> <head> <title>register</title> <script th:src="@{/js/jquery-2.1.1.min.js}" type="text/javascript"></script> <script th:src="@{/js/vue.min.js}" type="text/javascript"></script> <script src="https://unpkg.com/element-ui/lib/index.js"></script> <title>登录表单</title> <meta name="keywords" content="登录表单"/> <!-- Meta-Tags --> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script> <!-- //Meta-Tags --> <!-- Style --> <link rel="stylesheet" href="/./css/style.css" type="text/css" > </head> <body> <h1>注册表单</h1> <div class="container w3layouts agileits"> <div class="register w3layouts agileits" id="app"> <h2>注 册</h2> <form action="#" method="post"> <input type="text" Name="Name" placeholder="用户名" required=""> <input type="text" Name="Email" placeholder="邮箱" required=""> <input type="password" Name="Password" placeholder="密码" required=""> <input type="text" Name="Phone Number" placeholder="手机号码" required=""> </form> <div class="send-button w3layouts agileits"> <button @click="turnToRegister">注册</button> </div> <div class="clear"></div> </div> <div class="clear"></div> </div> <script> //新建一个Vue对象。 new Vue({ //绑定作用域 el: "#app", //绑定数据 data: {//双向绑定数据 user: { name: "", password: "", } }, //绑定方法; methods: { addOne() { //适用ajax进行数据交互 $.ajax({ url: "/user/insertOne",//请求的路径 type: "post",//请求的方式 data: { name: this.user.name,//获取user里面的数据并且进行绑定; password: this.user.password, }, //返回数据的格式 dataType: "json", //成功返回方式 success: function (rs) { if (rs.status == 200) {//rs获取状态码看是否成功 layer.alert(rs.msg, {icon: 6}, function () { //获取ifram层的窗口名 var frameIndex = parent.layer.getFrameIndex(window.name); parent.layer.close(frameIndex); parent.location.reload() location.href="/login" }) } else { layer.alert(rs.msg, {icon: 5}, function () { //获取ifram层的窗口名 var frameIndex = parent.layer.getFrameIndex(window.name); parent.layer.close(frameIndex); }) } } }) } } }) </script> </body> </html> 帮我以上代码实现注册功能成功后,新增一个小弹窗,弹窗内容是注册成功
05-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值