最终实现效果如下图:

具体来说就是实现了checkbox自定义选中和为选择样式,菜单项根据不同位置设置不同背景.

先上整体布局文件代码:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#DFE1E0"

android:orientation="vertical">

style="@style/SettingItemTop"

android:background="@drawable/setting_list_top"

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

style="@style/MySettingText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="开启通知"

/>

style="@style/MyCheckBox"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

style="@style/SettingItemMiddle"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

style="@style/MySettingText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="开启铃声"

/>

style="@style/MyCheckBox"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

style="@style/SettingItemBottom"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

style="@style/MySettingText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="开启震动"

/>

style="@style/MyCheckBox"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

注意到:

style="@style/MySettingText"

这一句,这里用了style.xml这个文件来控制样式.Android实际开发中,会有很多时候一些部件的属性是要重复出现的,如果每个控件都要单独的把这些属性单独的输入一次,那样会很没有效率.可以将重复的代码添加到style.xml中,设置成一种样式,在用到这些属性是引用这个样式即可.

style="@style/MySettingText"这个是设置文字的属性,代码如下:

10dp

6

这里仅用了两个属性.开发中可以根据实际需要自行修改.以后每个设置项的文字不需要再把这些属性再添加一边,引用一下这个style即可.

CheckBox样式自定义用到了selector.

style="@style/MyCheckBox"

此句对应的代码:

@drawable/check

10dp

1

注意到此句:

@drawable/check

这里就用了selector自定义样式.

在res/drawable下建立一名为check(自定)的xml文件,代码如下:

其中

@drawable/on为选择时checkbox的图像,

@drawable/off反之.

还注意到菜单中第一项上方为圆角,中间项为四角都为方,最后一项为下部圆角,这个就是通过设置不同的背景图片实现的了,具体不细表.

android开发UI界面布局教学,android UI学习 -- 设置界面的布局(包括style的使用,selector的使用,Checkbox自定义样式,菜单项的样式)...相关推荐

  1. Android开发— 2016_最流行的Android组件、工具、框架大全(二)

    2019独角兽企业重金招聘Python工程师标准>>> 泡在网上的日子 首页 代码 话题 问答 标签 关于 登录注册 首页 › 安卓开发 › android开发 Android开发- ...

  2. Android开发经验谈-很少有人会告诉你的Android开发基本常识,经验谈android

    转载:http://www.android100.org/html/201507/15/165084.html Android开发经验谈-很少有人会告诉你的Android开发基本常识,经验谈andro ...

  3. Android 开发艺术探索——第十章 Android的消息机制

    Android 开发艺术探索--第十章 Android的消息机制读书笔记 Handler并不是专门用于更新UI的,只是常被用来更新UI 概述 Android的消息机制主要值得就是Handler的运行机 ...

  4. Android开发-AMD平台如何使用Android studio自带模拟器

    Android开发-AMD平台如何使用Android studio自带模拟器 前言 AMD开启虚拟化VT win10专业版开启 win10家庭版开启 创建Android模拟器 前言 现在Android ...

  5. Android开发入门与实战之Android应用安装卸载

    当一个Android开发者完整的开发完毕一个程序应用软件结束后要进行软件测试,这就是软件测试员的来历,那么在这之前,要进行Android开发应用的安装与卸载. Android开发入门与实战之Andro ...

  6. android addview指定位置,Android开发中,请问当在一个视图中addView另一个布局视图时为什么报错?...

    Android开发中,我在一个视图中addView另一个布局视图(该视图通过inflate加载获得,其中root为null即没有附加parent视图),为什么还是会报错误: The specified ...

  7. Android开发的之基本控件和详解四种布局方式

    Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...

  8. 为什么Android项目mainactivity中有一个变量R_【Android开发入门教程】二.Android应用程序结构分析!...

    一.新建HelloWorld项目: 1.打开Eclipse,点击"File"->"New"->"Project"-Android ...

  9. Android开发面试经——2.常见Android基础笔试题

     标签: androidAndroid基础Android面试题Android笔试题 2015-03-12 15:04 3361人阅读 评论(3) 收藏 举报  分类: Android开发(29)  版 ...

最新文章

  1. Linux磁盘管理----分区格式化挂载fdisk、mkfs、mount
  2. [云炬创业学笔记]第三章商业创意的发掘与评估测试1
  3. Educational Codeforces Round 75 (Rated for Div. 2) E2. Voting (Hard Version) 贪心
  4. Ph.D Grind 阅读感想 By 张雄
  5. 程序员常用字体(vs2008字体修改方案)
  6. 如何在jsp页面中连接mysql数据库_如何使用JSP访问MySQL数据库
  7. WebDev.WebServer.exe遇到问题需要关闭
  8. 《Python数据分析》第二版.第二章.[学习笔记][Jupyter notebook]
  9. pd怎么转成mysql_powerdesigner中实现PDM到MYSQl数据库的转换《转》
  10. python 深度学习超参优化
  11. 《剑指offer》第二章小结(1)——链表的基本操作
  12. oracle导出数据只能9999,批量快速的导入导出Oracle的数据
  13. 计算机信息管理学书心得,学习erp的心得体会共计5篇
  14. 计算机算法需要什么数学知识,计算机编程算法和数学有什么关系?
  15. 单片机之汇编语言和C语言(以PIC单片机为例)
  16. PCB学习笔记——原理图编译与检查
  17. 用 FFMPEG 合并 MP4 视频
  18. Microsoft Surface
  19. Python模块之Pandas模块学习笔记
  20. 写给情人,写给情人节,写给即将开始的新一年

热门文章

  1. windows php7 apache,windows系统下php7+apache2.4环境搭建
  2. 韩顺平php视频笔记35 php运行过程
  3. pagehelper工具类_PageHelper最佳实践
  4. wepyjs小程序组件调用pages页面的方法
  5. html登陆l判断,html作业登陆界面
  6. mysql读写分离-借助中间键mycat
  7. 列标题 如何删除gridcontrol_GridControl简单属性操作
  8. python list索引遍历_在python中遍历dict和list
  9. python多分类_python中多类分类的ROC或CAP曲线
  10. python_格式化输出(%用法和format用法)