Android资源访问——尺寸资源
2015-02-25 17:46
232 查看
尺寸资源
(1)认识dp
主布局(activity_main.xml):
运行结果:
说明:
dp是一种长度单位,与屏幕的像素密度有关系(若设备为160px/英寸,则dp=px),主要用于描述组件宽高。
此外,类似的长度单位还有sp(主要描述文字,为比例大小)、pt(描述文字大小,意为磅)、mm(毫米)、in(英寸)、px(像素)。
(2)在values下新建XML文件,命名为dimen。
原来的values文件中本来就有一个文件叫做dimens,在其中补充写入代码
在主布局文件中使用它(dp10)
运行程序,效果相同。
(1)认识dp
主布局(activity_main.xml):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <View android:background="@color/red" android:layout_width="10dp" android:layout_height="50dp"/> <View android:background="@color/green" android:layout_width="20dp" android:layout_height="50dp"/> <View android:background="@color/blue" android:layout_width="30dp" android:layout_height="50dp"/> <View android:background="#FFFF00FF" android:layout_width="40dp" android:layout_height="50dp"/> </LinearLayout>
运行结果:
说明:
dp是一种长度单位,与屏幕的像素密度有关系(若设备为160px/英寸,则dp=px),主要用于描述组件宽高。
此外,类似的长度单位还有sp(主要描述文字,为比例大小)、pt(描述文字大小,意为磅)、mm(毫米)、in(英寸)、px(像素)。
(2)在values下新建XML文件,命名为dimen。
原来的values文件中本来就有一个文件叫做dimens,在其中补充写入代码
<dimen name="dp10">10dp</dimen>
在主布局文件中使用它(dp10)
<View android:background="@color/red" android:layout_width="@dimen/dp10" android:layout_height="50dp"/>
运行程序,效果相同。
相关文章推荐
- 2012-6-13 Android中的资源访问——尺寸资源
- 2012-6-13 Android中的资源访问——尺寸资源
- Android-用户资源访问:字符串、颜色、尺寸、布局、数组、Drawable
- 一个android访问http资源的便捷工具类——HttpHelper
- Android中使用HttpGet和HttpPost访问HTTP资源(一)
- 深入Android通过Apache HTTP访问HTTP资源
- 4.1 Android如何访问资源
- 【原创】一个android访问http资源的便捷工具类——HttpHelper
- android 访问图片资源
- Android 访问HTTP资源
- android学习—— 通过包名访问其他apk下的资源
- Android进阶2之Https访问网络资源(获取网络图片)
- Android(OPhone) 学习笔记 - 资源的访问和配置
- 一个android访问http资源的便捷工具类——HttpHelper
- Android通过Apache HTTP访问HTTP资源
- 一个android访问http资源的便捷工具类——HttpHelper
- [Android]正确地访问网络资源----Proxy的使用
- android中的资源访问
- [转]深入Android通过Apache HTTP访问HTTP资源
- Android进阶2之Https访问网络资源(获取网络图片)