xml布局内容总结(四)--Android
(1)对于xml编写界面较复杂的情况下,使用include会使得编写和查看更清楚
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include android:id="@+id/hi1" layout="@layout/health_info1" />
<include android:id="@+id/hi2" layout="@layout/health_info2" />
<include android:id="@+id/hi3" layout="@layout/health_info3" />
<include android:id="@+id/hi4" layout="@layout/health_info4" />
<include android:id="@+id/hi5" layout="@layout/health_info5" />
</LinearLayout>
这里health_info1到health_info5是5个布局文件,相应于界面中的5个模块,每一个模块单独200行左右,假设在单独的模块中,不论是改动还是查看都比較easy,假设不适用include,整个布局文件就是1000行左右。无论是改动还是查看都比較麻烦,类似于代码中函数的调用。
CheckBox hiCbPs1;
hiCbPs1=(CheckBox)findViewById(R.id.hi1).findViewById(R.id.hicbps1);
这是代码中的使用方法
(2)自己定义view的使用。在开发产品时,有时候会碰到一些须要自己进行绘制的view增加到界面中
加入到到xml中的使用方法
<com.jxj.view.BigDialView
android:id="@+id/healthstatedial"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:layout_margin="5dip"
android:layout_gravity="center"
android:scaleType="centerInside"
/>
com.jxj.view 是包名 BigDialView是自己定义的类名 com.jxj.view.BigDialView是完整的路径
这里常常easy出错的问题就是xml中找不到该类,原因通常是未定义这个类,还是就是包名或类名写错导致xml找不到
(3)这个是在LoonAndroid框架中看到的。认为挺好用
基本全部的控件都会用到这两条语句
android:layout_width="fill_parent"
android:layout_height="wrap_content"
在LoonAndroid框架中看到了这样的使用方法比較简单,用一条语句替换了
<RelativeLayout
android:id="@+id/top_head"
style="@style/w_full_h_wrap"
android:background="@drawable/head_back"
android:orientation="horizontal" >
等同于
<RelativeLayout
android:id="@+id/top_head"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/head_back"
android:orientation="horizontal" >
想要使用这样的方法。仅仅需在values文件夹下加入
themes_basic.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 全屏幕拉伸 -->
<style name="w_h_full">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
<!-- 高度和屏幕高度一样 宽度自适应 -->
<style name="w_wrap_h_full">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">fill_parent</item>
</style>
<!-- 宽度和屏幕宽度一样 高度自适应 -->
<style name="w_full_h_wrap">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<!-- 固定自身大小 -->
<style name="w_wrap_h_wrap">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
xml布局内容总结(四)--Android的更多相关文章
- xml布局内容总结(一)--Android
关于安卓项目中xml的使用非常多.为了达到一些好的UI效果.须要对xml比較熟练.会使用非常多的小技巧,本人准备对这些小技巧进行整理和总结,希望进行分享和交流. 关于weight的使用,因为weigh ...
- xml布局内容总结(三)--Android
关于xml中经经常使用到边框及边框效果,在此进行一下总结. 3.border(边框及边框效果) (1)直角边框线 <LinearLayout android:layout_wid ...
- 通过在xml布局文件中设置android:onClick=""来实现组件单击事件
在布局中出现android:onClick=""语句: <Button android:id="@+id/call_button" android:onC ...
- android xml布局文件属性说明
android xml布局文件属性说明 [摘]android xml布局文件属性说明 LinearLayout和RelativeLayout 共有属性:java代码中通过btn1关联次控件androi ...
- 20165205 2017-2018-2 《Java程序设计》实验四 Android程序设计
20165205 2017-2018-2 <Java程序设计>实验四 Android程序设计 实验内容 实验四 Android程序设计-1 Android Stuidio的安装测试: 参考 ...
- 20155314 2016-2017-2 《Java程序设计》实验四 Android程序设计
20155314 2016-2017-2 <Java程序设计>实验四 Android程序设计 实验任务 基于Android Studio开发简单的Android应用并部署测试 了解Andr ...
- android 开发 使用自定义布局实现标题栏复用(标题栏内容自定义:使用代码实现和xml布局自定义属性2种办法实现)
在个人学习的情况下可能很少使用自定义布局去实现大量复用的情况下,但是在一个开发工作的环境下就会使用到大量复用的自定义控件. 实现思维: 1.写一个xml的布局,用于标题栏的样式,并且添加在标题栏中你想 ...
- Android中将xml布局文件转化为View树的过程分析(下)-- LayoutInflater源码分析
在Android开发中为了inflate一个布局文件,大体有2种方式,如下所示: // 1. get a instance of LayoutInflater, then do whatever yo ...
- 仿酷狗音乐播放器开发日志二十四 选项设置窗体的实现(附328行xml布局源码)
转载请说明原出处,谢谢~~ 花了两天时间把仿酷狗的选项设置窗体做出来了,当然了只是做了外观.现在开学了,写代码的时间减少,所以整个仿酷狗的工程开发速度减慢了.今天把仿酷狗的选项设置窗体的布局代码分享出 ...
随机推荐
- httpclient就是个能发送http连接的工具包,包括能发送post请求和get请求
1.httpclient就是个能发送http连接的工具包,包括能发送post请求和get请求. http 连接一次就有返回流.http是个双向的嘛.只有连接了,就会有输出返回流. 所以在执行http连 ...
- spring mvc常用知识点总结
1.spring mvc是靠spring 启动的.通过springjar包的org.springframework.web.servlet.DispatcherServlet这个servlet类具体启 ...
- skimage的安装,scikit-image
在mac上面的安装: pip install -U scikit-image
- [ES2018] Two ways to write for-await-of
// Asynchronous iteration --> Symbol.asyncIterator async function main() { const syncIterable = [ ...
- Wing IDE 怎样设置 python版本号
机器上同一时候装了Python3和Python2,使用Wing IDE, 由于Python2和3是有非常大的差别的,所以时不时的须要更改IDE使用的Python版本号.以下介绍方法: 1.打开Edit ...
- poj1363——Rails
Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...
- 发送HTTP请求 -- HttpUtil
1. package com.step.utils; import java.io.IOException; import java.net.URLDecoder; import java.util. ...
- linux文件上传下载
上传本地文件到服务器:scp 文件名 账号@服务器IP:文件路径eg:scp test.txt root@192.168.0.123:/tmp/服务器文件下载到本地:scp 账号@服务器IP:文件 本 ...
- 一天一个算法:C语言解答杨辉三角
杨辉三角形是形如:11 11 2 11 3 3 11 4 6 4 1的三角形,其实质是二项式(a+b)的n次方展开后各项的系数排成的三角形,它的特点是左右两边全 ...
- Elasticsearch之重要核心概念(cluster(集群)、shards(分配)、replicas(索引副本)、recovery(据恢复或叫数据重新分布)、gateway(es索引的持久化存储方式)、discovery.zen(es的自动发现节点机制机制)、Transport(内部节点或集群与客户端的交互方式)、settings(修改索引库默认配置)和mappings)
Elasticsearch之重要核心概念如下: 1.cluster 代表一个集群,集群中有多个节点,其中有一个为主节点,这个主节点是可以通过选举产生的,主从节点是对于集群内部来说的.es的一个概念就是 ...