Android开发之merge结合include优化布局

Android开发之merge结合include优化布局,第1张

概述merge结合include优化android布局,效果不知道,个人感觉使用上也有很大的局限,不过还是了解一下,记录下来。

merge结合include优化androID布局,效果不知道,个人感觉使用上也有很大的局限,不过还是了解一下,记录下来。

布局文件都要有根节点,但androID中的布局嵌套过多会造成性能问题,于是在使用include嵌套的时候我们可以使用merge作为根节点,这样可以减少布局嵌套,提高显示速率。

<?xml version="1.0" enCoding="utf-8"?><merge xmlns:androID="http://schemas.androID.com/apk/res/androID" > <TextVIEw  androID:layout_wIDth="wrap_content"  androID:layout_height="wrap_content"  androID:text="张三" /> <TextVIEw  androID:layout_wIDth="wrap_content"  androID:layout_height="wrap_content"  androID:text="李四" /> <TextVIEw  androID:layout_wIDth="wrap_content"  androID:layout_height="wrap_content"  androID:text="王五" /></merge>

上面的界面在显示的时候会自动嵌套到下面的文件中。

<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" androID:orIEntation="horizontal" tools:context="com.example.vIEwstub.MainActivity" > <include layout="@layout/top"/> <TextVIEw  androID:layout_wIDth="wrap_content"  androID:layout_height="wrap_content"  androID:text="@string/hello_world" /> <button  androID:ID="@+ID/toggle"  androID:layout_wIDth="wrap_content"  androID:layout_height="wrap_content"  androID:onClick="onClick"  androID:text="显示/隐藏" /> <VIEwStub  androID:ID="@+ID/vs"  androID:layout_margin="50dp"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent"  androID:inflatedID="@+ID/inflated_ID"  androID:layout="@layout/vIEw_stub_layout" /></linearLayout>

我为什么说这个局限性比较大呢?因为merge中的空间显示的使用会采用主布局文件的方式来显示,比如我这里主布局是linearlayout且是水平排列,那么merge中的元素显示出来之后也是水平排列,可是我如果想让merge中的元素垂直排列呢?抱歉,做不到。

原文链接:http://blog.csdn.net/u012702547/article/details/47133647

以上就是本文的全部内容,希望对大家学习AndroID软件编程有所帮助。 

总结

以上是内存溢出为你收集整理的Android开发之merge结合include优化布局全部内容,希望文章能够帮你解决Android开发之merge结合include优化布局所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1149166.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存