一、字符串资源
定义
- AS开发界面 res 文件夹下 values 目录 string xml 文件中定义字符串资源
使用
- xml 中直接使用,前面用过很多次了
- java代码中使用:
getResources().getString(id)
二、颜色资源
- java文件中获取颜色资源:
getColor(id)
三、尺寸资源
- 我的AS版本中创建应用不会自动创建dimens xml 文件,手动创建即可
- java文件中获取尺寸资源:
getResources().getDimension(id)
四、布局资源
- 使用
include
标签在一个布局文件中引用另一个布局文件 - 使用
include
标签的 layout 属性指定包含的布局文件
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手势测试!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
layout="@layout/include_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv1" />
五、数组资源
三种array
<array>
:啥子类型我都是可以装的<integer-array>
<string-array>
数组示例
六、图像资源
1、关于9patch图片
9patch图片有什么用
- 普通的图片进行拉伸的时候出现图案的失真
- 9patch图片在进行缩放拉伸的时候不会出现图像的失真
- 9patch图不会失真的原因是我们制作9patch图的时候指定了图片哪些部分可以拉伸,哪些部分不能拉伸,这样就能够保证我们的图片在使用的时候不会失真
- 9patch图和普通图片的不同在于四周会有黑线,这些黑线就是用来指定可以拉伸的区域的
- 9patch图不能通过一般的修图软件进行制作,要使用专门的工具
9patch图片制作使用
- 安卓SDK里面一般会有这么一个工具draw9patch,这个就是用来制作 9patch图片的
- 工具的基本界面如上面的图所示,使用很简单,没啥可说
- 制作好 9patch图直接复制到工程的目录中进行使用即可
- 最后附一张使用9patch图和没有使用9patch图的效果
1.9patch图详细的说明参考:https://www.jianshu.com/p/3fd048644e3f
2.制作9patch图的软件不只这一个,ps好像也是可以用来做9patch的