iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android开发中include控件用法分析
  • 688
分享到

Android开发中include控件用法分析

android开发includeAndroid 2022-06-06 07:06:37 688人浏览 八月长安
摘要

本文实例讲述了Android开发中include控件用法。分享给大家供大家参考,具体如下: 我们知道,基于Android系统的应用程序的开发,界面设计是非常重要的,它关系着用户

本文实例讲述了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>

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

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

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

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

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

您可能感兴趣的文章:Android开发之merge结合include优化布局Android编程之include文件的使用方法android使用include调用内部组件的方法Android中使用include标签和merge标签重复使用布局解析android中include标签的使用Android控件系列之TextView使用介绍Android控件之ImageView用法实例分析Android控件ListView用法(读取联系人示例代码)Android AutoCompleteTextView控件使用实例Android控件之EditView常用属性及应用方法


--结束END--

本文标题: Android开发中include控件用法分析

本文链接: https://www.lsjlt.com/news/23611.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android开发之拖动条和评分组件用法分析
    本文实例讲述了Android开发之拖动条和评分组件用法。分享给大家供大家参考,具体如下:今天闲着没事做就拿出了Android书接着学习,android就是组件多有时候还会弄混淆了。这次介绍的是拖动条和评分组件,这2个组件也是超级简单的下面就...
    99+
    2023-05-30
    android 拖动条 评分组件
  • Android开发中怎么使用自绘控件
    Android开发中怎么使用自绘控件?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。第一步,在attrs.xml中定义控件的属性定义line_color这个属性主要就是为了控件兼...
    99+
    2023-05-31
    android roi
  • android控件开发的方法是什么
    Android控件开发的方法主要有以下几种:1. 基于XML布局文件进行控件的开发:可以使用XML布局文件来定义控件的外观和布局,然...
    99+
    2023-09-14
    android
  • Android开发中使用WebView控件浏览网页的方法详解
    本文实例讲述了Android开发中使用WebView控件浏览网页的方法。分享给大家供大家参考,具体如下:项目中遇到数学展示问题,常规的Textview显示处理不了数学公式,利用图片生成对服务器又产生较大压力,经过查询,可以通过webview...
    99+
    2023-05-30
    android webview roi
  • Android开发怎么实现RatingBar星级评分控件
    本篇内容介绍了“Android开发怎么实现RatingBar星级评分控件”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!实践过程初识Ratin...
    99+
    2023-07-02
  • Android开发手册RatingBar星级评分控件实例
    目录实践过程初识基本属性点击事件自定义样式实践过程 初识 RatingBar是基于SeekBar和ProgressBar的扩展,用星型来显示等级评定。 通常应用场景是在用户评价那,如...
    99+
    2024-04-02
  • Android开发Retrofit源码分析
    目录项目结构retrofit 使用Retrofit #createServiceMethod #parseAnnotationsHttpServiceMethod#parseAnno...
    99+
    2024-04-02
  • Android开发中播放声音的两种方法分析
    本文实例讲述了Android开发中播放声音的两种方法。分享给大家供大家参考,具体如下:在Android中,音频、视频等多媒体元素的加入,使得应用程序的用户体验更好。可以说,现在的手机,已经远远不只作为通信工具,更成为娱乐、办公的必备产品。A...
    99+
    2023-05-30
    android 播放 声音
  • Android开发中使用RatingBar UI控件实现一个星星评分功能
    这期内容当中小编将会给大家带来有关Android开发中使用RatingBar UI控件实现一个星星评分功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。具体内容如下继承关系AppCompatRatingB...
    99+
    2023-05-31
    android ratingbar roi
  • Android实现仪表盘控件开发
    仪表盘在工业软件中很常见,今天整一个图片式仪表盘控件(非几何图形绘制)。实现非常简单,一张背景图,一张指针。创建一个RelativeLayout布局文件,然后在里面布置好控件的位置,...
    99+
    2024-04-02
  • Android事件分发机制 ViewGroup分析
    目录整体流程源码分析前言: 事件分发从手指触摸屏幕开始,即产生了触摸信息,被底层系统捕获后会传递给Android的输入系统服务IMS,通过Binder把消息发送到activity,a...
    99+
    2024-04-02
  • 深入分析Android NFC技术 android nfc开发
    从概念,实现原理以及最红实现的源码等有助于大家对NFC技术有更深入的理解。NFC 是 Near Field Communication 缩写,即近距离无线通讯技术。可以在移动设备、消费类电子产品、PC 和智能控件工具间进行近距离无线通信。简...
    99+
    2023-05-30
  • Android事件分发机制示例分析
    Android事件类型 public boolean onTouchEvent(MotionEvent event) { switch (event.getActio...
    99+
    2024-04-02
  • Android开发之SD卡文件操作的示例分析
    这篇文章主要为大家展示了“Android开发之SD卡文件操作的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Android开发之SD卡文件操作的示例分析”这篇文章吧。具体如下:前面的文章...
    99+
    2023-05-30
    android sd卡
  • 如何在Android 开发中实现一个日历控件
    这期内容当中小编将会给大家带来有关如何在Android 开发中实现一个日历控件,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。一、主要功能支持农历、节气、常用节假日2、日期范围设置,默认支持的最大日期范围[...
    99+
    2023-05-31
    android roi
  • Android开发中GridView用法示例
    本文实例讲述了Android开发中GridView用法。分享给大家供大家参考,具体如下:Android的GridView控件用于把一系列的空间组织成一个二维的网格显示出来,应用的比较多的就是组合图片显示。下面我就详细讲一个例子。首先写一个类...
    99+
    2023-05-30
    android gridview idv
  • wen开发中高德地图WEB版基础控件的示例分析
    这篇文章主要为大家展示了“wen开发中高德地图WEB版基础控件的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“wen开发中高德地图WEB版基础控件的示例...
    99+
    2024-04-02
  • Android开发中Flutter组件怎么用
    这篇“Android开发中Flutter组件怎么用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Android开发中Flut...
    99+
    2023-06-30
  • Android AccessibilityService 事件分发原理分析总结
    目录AccessibilityService 监听事件的调用逻辑onAccessibilityEventonInterceptAccessibilityService 事件的外部来源...
    99+
    2024-04-02
  • Android开发Input系统触摸事件分发
    目录引言1. InputDispatcher 收到触摸事件1.1 截断策略查询2. InputDispatcher 分发触摸事件2.1 寻找触摸的窗口2.1.1 根据坐标找到触摸窗口...
    99+
    2023-03-02
    Android Input触摸事件分发 Android Input系统
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作