1.单位dp、dip、sp、pt、px、in、mm

这里引用StackOverFlow上的一个解答:

  • px is one pixel.
  • sp is scale-independent pixels.
  • dip is Density-independent pixels.( dip == dp is ture)
 
Here is the difference

dp
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
即:dp=160*px/dpi
 
sp
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
 
Remenber this:

You would use

  • sp for font sizes
  • dip for everything else
To make it absolutely clear - try to never use anything but sp or dp unless you absolutely have to. Using sp/dp will make your Android applications compatible with multiple screen densities and resolutions.
 
2.可见性invisible与gone
invisible:控件消失,点击事件失效,仍然占据着位置
gone:控件消失,布局位置被腾空
 
3.设置进度条Style
设置为水平:style="?android:attr/progressBarStyleHorizontal"
 
4.LinearLayout
想要在某一行设置一个EditText和Button, 让Button宽度包裹内容,让EditText占据屏幕剩余宽度
<EditText
android:id="@+id/input_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Type something"
/>
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
/> 
 
5.一个简易快速ListView,可显示一批String
private String[] data = { "Apple", "Banana", "Orange", "Watermelon",
"Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this, android.R.layout.simple_list_item_1, data);
ListView listView = (ListView) findViewById(R.id.list_view);
listView.setAdapter(adapter);
 
6.自定义Adapter时候重载getView()方法的作用
这个方法在每个子项被滚动到屏幕内的时候会被调用
 
7.ListView性能优化
使用Adapter中getView()方法的参数convertView,避免每次重复加载布局文件
使用ViewHolder来记录绑定的控件id与控件实例
 
8.编写聊天界面方式选择
使用一个布局,用于存储来往消息气泡,根据消息流向设置控件可见性
这样的方式要优于使用多个布局文件

《第一行代码--Android》阅读笔记之界面设计的更多相关文章

  1. 《第一行代码——Android》

    <第一行代码——Android> 基本信息 作者: 郭霖 丛书名: 图灵原创 出版社:人民邮电出版社 ISBN:9787115362865 上架时间:2014-7-14 出版日期:2014 ...

  2. 历时一年,我的著作《第一行代码——Android》已出版!

    前言 事实上我当初决定開始写博客的想法挺简单的,认为自己搞技术这么多年了,总应该要留下点什么.既然没能写出什么出色的应用,那至少也要留下点文字分享给大家,以指引在我后面的开发人员们,毕竟我也从前辈们的 ...

  3. 20172327 2018-2019-1 《第一行代码Android》第二章学习总结

    学号 2017-2018-2 <第一行代码Android>第二章学习总结 教材学习内容总结 - 活动是什么: 活动(Activity)是最容易吸引用户的地方,它是一种可以包含用户界面的组件 ...

  4. 20172327 2018-2019-1 《第一行代码Android》第一章学习总结

    学号 2018-2019-1 <第一行代码Android>第一章学习总结 教材学习内容总结 - Android系统架构: 1.Linux内核层 Android系统是基于Linux内核的,这 ...

  5. 第一行代码 Android 思维导图

    第一行代码 Android  思维导图

  6. 晒订单赢图灵图书,《第一行代码——Android》福利活动劲爆来袭!

    版权声明:本文出自郭霖的博客,转载必须注明出处. https://blog.csdn.net/sinyu890807/article/details/28863515 (已结束) 我的著作<第一 ...

  7. 第一行代码Android(第3版).pdf下载

    2020年人民邮电出版社出版的图书 <第一行代码Android(第3版)>是2020年4月人民邮电出版社出版的图书,作者是郭霖. 封面: 内容简介: <第一行代码 Android 第 ...

  8. 第一行代码 Android 第二版到货啦

    今日android第一行代码[第二版]已到,收获的季节到了 先看一下封面 书签: 以后就把空闲时间送给它吧 先来看一下本书的目录: 第1章 开始启程--你的第1行Android代码 第2章 先从看得到 ...

  9. 《第一行代码 android》 读书笔记:找出当前界面对应的Activity

    在android开发中找出当前界面对应的Activity,步骤如下: 新建一个BaseActivity继承自Activity,然后在BaseActivity中重写onCreate()方法,通过getC ...

随机推荐

  1. [Flex] PopUpButton系列 —— 判断下拉列表是否选中

    <?xml version="1.0" encoding="utf-8"?> <!--Flex中如何利用dataDescriptor属性和is ...

  2. [ActionScript 3.0] AS3 ConvolutionFilter卷积滤镜的应用

    ConvolutionFilter 类应用矩阵盘绕滤镜效果.卷积将输入图像的像素与相邻的像素合并以生成图像.通过卷积,可以实现大量的图像效果,包括模糊.边缘检测.锐化.浮雕和斜角.您可以将滤镜应用于任 ...

  3. Font-Awesome for android

    Font-Awesome 是为Bootstrap设计的一个图标集合字体,里面包含了300多个常用图标.使用Font-Awesome还具有如下优点: 1. 减少了图标的绘制工作 2. 可以设置图标的颜色 ...

  4. flask log

    import logging from logging.handlers import RotatingFileHandler from flask import Flask app = Flask( ...

  5. [SQL]SQL中把一个字段的数据分多行显示

    其实你完全可以写个自定义函数就OK了 . =================================================================== create func ...

  6. java使用jacob将office转pdf

    1.此处代码是把office文档转换成pdf的工具类,在BS架构的产品中,我们可以使用基于JS的pdf插件显示pdf文档,但是前提IE需要按照adobe的pdf软件,对于非IE不用安装.2.可以基于f ...

  7. 推荐一个PHP在线代码运行的网站

    地址:http://www.manongjc.com/runcode 该网站可以运行php代码.html代码.js代码, 对于初学者来说,免去了安装环境这一步.

  8. vc 取windows系统信息 版本 cpu信息 内存信息 ie版本信息 office版本

    头文件: /*! Copyright (C) *---------------------------------------------------------------------------- ...

  9. 使用eclipse上传项目到开源中国代码托管Git@osc教程

    创建项目 安装EGit插件 没有的话看下图 生成公钥 注册git账号 新建git项目 添加公钥 建立本地代码库 本文章版权归博主所有,如需转载请私信.

  10. JavaScript内置对象

    对象概述 JavaScript是一种基于对象的脚本语句,而不是面向对象的编程语言.对象就是客观世界存在的实体,具有属性和方法两方面特性. 访问对象的属性和方法的方式如下: 对象名.属性 对象名.方法名 ...