Android表示单位长度的方式通常有三种表示方式。

  距离单位☞px:表示屏幕实际的象素。例如,320*480的屏幕在横向有320个象素,在纵向有480个象素

  距离单位☞dp:dp = dpi    换算公式:px = dp*(dpi/160)      设置控件大小的通常用dp

  距离单位☞sp(与刻度无关的像素):  会随着用户设置的字体的大小而改变       设置控件的文本大小通常用sp

如果使用dp和sp,系统会根据屏幕密度的变化自动进行转换。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:layout_width="160dp"
android:layout_height="100dp"
android:layout_marginTop="300dp"
android:layout_marginLeft="0dp"
android:paddingTop="20dp"
android:textSize="30sp"
android:background="#FF0000"
android:text="@string/hello_world" /> </LinearLayout>
layout_margin(外边距):是控件边缘相对于父控件的边距
 
layout_padding(内边距):是控件内容相对于控件边缘的边距
 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="60dp"
android:layout_marginBottom="100dp"
android:layout_height="wrap_content"
android:text="测试按钮一"></Button> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20sp"
android:paddingTop="5sp"
android:text="测试按钮一"></Button> <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_height="wrap_content"
android:text="测试按钮一"></Button>
</LinearLayout>

最新文章

  1. Markdown的使用---现学现用
  2. yii2 登录用户和未登录用户使用不同的 layout
  3. 在Mac电脑上为iPhone或iPad录屏的方法
  4. jQuery原生框架-----------------事件
  5. ibatis
  6. 微信小程序官方文档错误整理
  7. php生成excle
  8. 安装及升级node
  9. DAG的生成
  10. M - 昂贵的聘礼 - poj1062
  11. java读取properties 文件信息
  12. mysql如何直接查出从1开始递增的数
  13. linux安装mysql5.7.19
  14. Win下安装nvm
  15. js 选项卡制作
  16. while 循环居然可以用else
  17. VisualSVN server搭建装配和指定IP或域名
  18. UVA 10090 Marbles(扩展欧几里得)
  19. ZOJ3768 Continuous Login 2017-04-14 12:47 45人阅读 评论(0) 收藏
  20. 给上传文件的input控件“美容”

热门文章

  1. iOS ipa包瘦身,iOS8及以下text段超60MB
  2. 【PyTorch深度学习60分钟快速入门 】Part1:PyTorch是什么?
  3. Ubuntu安装设置nginx和nohup常用操作
  4. 【学习笔记】深入理解async/await
  5. 部署DTCMS到Jexus遇到的问题及解决思路---部署
  6. spark任务提交流程
  7. html5新特性学习笔记
  8. webpack单独打包一个less文件
  9. 【读书笔记】iOS-深入解剖对等网络
  10. Python&#160;关于Python函数参数传递方式的一点探索