Android开发中include控件用法分析

Android开发中include控件用法分析,第1张

概述本文实例讲述了Android开发中include控件用法。分享给大家供大家参考,具体如下:

本文实例讲述了AndroID开发中include控件用法。分享给大家供大家参考,具体如下:

我们知道,基于AndroID系统的应用程序的开发,界面设计是非常重要的,它关系着用户体验的好坏。一个好的界面设计,不是用一个xml布局就可以搞定的。当一个activity中的控件非常多的时候,所有的布局文件都放在一个xml文件中,很容易想象那是多么糟糕的事情!笔者通过自身的经历,用include控件来解决这个问题,下面是一个小例子,仅仅实现的是布局,没有响应代码的设计。

user.xml文件内容如下:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  androID:layout_wIDth="fill_parent"  androID:layout_height="fill_parent"  androID:orIEntation="horizontal" >  <TextVIEw    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:text="用户名: " />  <EditText    androID:layout_wIDth="150dp"    androID:layout_height="wrap_content"    androID:ID="@+ID/username"    androID:hint="请输入用户名"    /></linearLayout>

passwd.xml文件内容如下:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  androID:layout_wIDth="fill_parent"  androID:layout_height="fill_parent"  androID:orIEntation="horizontal" >   <TextVIEw    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:text="密   码:" />  <EditText    androID:layout_wIDth="150dp"    androID:layout_height="wrap_content"    androID:ID="@+ID/passWd"    androID:hint="请输入密码"    /></linearLayout>

login.xml文件内容如下:

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  androID:layout_wIDth="fill_parent"  androID:layout_height="fill_parent"  androID:orIEntation="horizontal" >  <button    androID:layout_wIDth="80dp"    androID:layout_height="wrap_content"    androID:ID="@+ID/bt"    androID:hint="确定"    />  <button    androID:layout_wIDth="80dp"    androID:layout_height="wrap_content"    androID:ID="@+ID/reset"    androID:layout_toRightOf="@ID/bt"    androID:hint="重置"    /></relativeLayout>

main.xml文件内容如下:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  androID:layout_wIDth="fill_parent"  androID:layout_height="fill_parent"  androID:orIEntation="vertical"  androID:layout_alignParentBottom="true"><relativeLayout  androID:layout_wIDth="fill_parent"  androID:layout_height="fill_parent"  androID:orIEntation="vertical"  androID:layout_alignParentBottom="true"> <linearLayout  androID:layout_wIDth="fill_parent"  androID:layout_height="wrap_content"  androID:ID="@+ID/head"  androID:layout_alignParenttop="true">   <include   androID:layout_wIDth="fill_parent"   layout="@layout/user">   </include> </linearLayout> <linearLayout  androID:layout_wIDth="fill_parent"  androID:layout_height="wrap_content"  androID:ID="@+ID/mIDdle"  androID:layout_below="@ID/head"  androID:layout_alignParentleft="true">   <include   androID:layout_wIDth="fill_parent"   layout="@layout/passwd">   </include>  </linearLayout>  <linearLayout  androID:layout_wIDth="fill_parent"  androID:layout_height="wrap_content"  androID:ID="@+ID/foot"  androID:layout_below="@ID/mIDdle"  androID:layout_alignParentRight="true">   <include   androID:layout_wIDth="fill_parent"   layout="@layout/login">   </include>   </linearLayout></relativeLayout></linearLayout>

程序运行结果如下:

如果在main.xml中这样写:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  androID:layout_wIDth="fill_parent"  androID:layout_height="fill_parent"  androID:orIEntation="vertical"  androID:layout_alignParentBottom="true">   <include   androID:layout_wIDth="fill_parent"   layout="@layout/user">   </include>   <include   androID:layout_wIDth="fill_parent"   layout="@layout/passwd">   </include>   <include   androID:layout_wIDth="fill_parent"   layout="@layout/login">   </include></linearLayout>

那么该情况下的运行结果如下:

@H_404_45@

很显然运行结果与预期不符,接下来的四个控件出不来,为什么呢?(想必大家在做实验的时候,肯定遇到过这个问题!)

其实关键的地方是main文件中对各个xml的布局,没有相应的布局,结果是非常惨的,大家可以根据我的代码在修改下相应的布局,体会下main中布局的重要性!

更多关于AndroID相关内容感兴趣的读者可查看本站专题:《Android视图View技巧总结》、《Android图形与图像处理技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体 *** 作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》、《Android布局layout技巧总结》及《Android控件用法总结》

希望本文所述对大家AndroID程序设计有所帮助。

总结

以上是内存溢出为你收集整理的Android开发中include控件用法分析全部内容,希望文章能够帮你解决Android开发中include控件用法分析所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存