android中的资源文件
来源:互联网 发布:java ireport 打印 编辑:程序博客网 时间:2024/06/07 19:45
1.android中的提供了很多资源文件,资源文件放在res/下,或者将raw/下的放在assets下也行。有这些类型:都是xml文件
animator/ 属性动画
anim/ 视图动画
color/ a state list of colors 由颜色值对应一个状态
drawable/ 图片,shape,Animation drawables,Nine-Patches
mipmap/ 图片
layout/ 布局文件
menu/ 菜单文件
raw/ 保留文件的原始格式 ,音视频,Resources.openRawResource()
values/ arrays.xml,colors.xml,dimens.xml,strings.xml,styles.xml
xml/ Resources.getXML(). xml形式的配置文件
2.也可以对这些资源上做一些限定,例如不同的语言环境对应的values,不同的分辨率图片对应的drawable等待。
限定符:作用就是在对应的设备环境下使用对应的资源
MCC and MNC ,mcc310 mcc310-mnc004
Language and region ,en
Layout Direction ,ldrtl ldltr(默认)
smallestWidth ,sw320dp
Available width ,w720dp
Available height ,h720dp
Screen size:
small 320x426 dp
normal320x470 dp
large480x640 dp
xlarge720x960 dp
Screen aspect long,notlong
Round screen round,notround
Screen orientation port,land
Night mode ight,notnight
Screen pixel density (dpi)
ldpi 120dpi.
mdpi 160dpi.
hdpi 240dpi.
xhdpi320dpi.
xxhdpi 480dpi.
xxxhdpi 640dpi.
nodpi 对bitmap resources 不缩放
tvdpi 213dpi
anydpi 不考虑dpi ,vector drawables.
There is a 3:4:6:8:12:16 scaling ratio between the six primary densities (
Touchscreen type notouch,finger(触摸屏)
3.资源访问,使用id即可。R.drawable.my_background_image,R.string.hello_message
4,资源变更:
<span style="font-size:14px;">@Overridepublic void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Checks the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); }}</span>
5.具体资源:
a.Animation Resources:
Property Animation有Animator, ValueAnimator, ObjectAnimator, or AnimatorSet.
View Animation有Tween animation:<set><alpha><scale><translate><rotate>
Frame animation :<animation-list>
b.Color State List Resource:
<selector>
c.Drawable Resources
有Bitmap File, Creates a BitmapDrawable.
有Nine-Patch File, Creates a NinePatchDrawable.
有Layer List ,Creates a LayerDrawable.
有State List,Creates a StateListDrawable.
有Level List,Creates a LevelListDrawable.
有Transition Drawable,Creates a TransitionDrawable.
有Inset Drawable,Clip Drawable,Scale Drawable,Shape Drawable
d.Layout Resource:
<menu>
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.example_menu, menu);
e.String Resources
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
使用html标签, <string name="welcome">Welcome to <b>Android</b>!</string>
使用Spannables
f.Style Resource
使用style来定义Theme,控件样式
<style
name="style_name"
parent="@[package:]style/style_to_inherit">
<item
name="[package:]style_property_name"
>style_value</item>
</style>
g.More Resource Types
Bool
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><resources> <bool name="bool_name" >[true | false]</bool></resources></span>
Color
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><resources> <color name="color_name" >hex_color</color></resources></span>Dimension:dp,sp,px
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><resources> <dimen name="dimension_name" >dimension</dimen></resources></span>
ID
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><resources> <item type="id" name="id_name" /></resources></span>
Integer
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><resources> <integer name="integer_name" >integer</integer></resources> </span>Integer Array
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><resources> <integer-array name="integer_array_name"> <item >integer</item> </integer-array></resources> </span>Typed Array
这个在自定义控件中,获取自定义属性时我们用到过
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><resources> <array name="icons"> <item>@drawable/home</item> <item>@drawable/settings</item> <item>@drawable/logout</item> </array> <array name="colors"> <item>#FFFF0000</item> <item>#FF00FF00</item> <item>#FF0000FF</item> </array></resources>Resources res = getResources();TypedArray icons = res.obtainTypedArray(R.array.icons);Drawable drawable = icons.getDrawable(0);TypedArray colors = res.obtainTypedArray(R.array.colors);int color = colors.getColor(0,0);</span>
6.manifest文件:
Manifest的结构
<?xml version="1.0" encoding="utf-8"?>
<manifest>
<uses-permission />
<permission />
<permission-tree />
<permission-group />
<instrumentation />
<uses-sdk />
<uses-configuration />
<uses-feature />
<supports-screens />
<compatible-screens />
<supports-gl-texture />
<application>
<activity>
<intent-filter>
<action />
<category />
<data />
</intent-filter>
<meta-data />
</activity>
<activity-alias>
<intent-filter> . . . </intent-filter>
<meta-data />
</activity-alias>
<service>
<intent-filter> . . . </intent-filter>
<meta-data/>
</service>
<receiver>
<intent-filter> . . . </intent-filter>
<meta-data />
</receiver>
<provider>
<grant-uri-permission />
<meta-data />
<path-permission />
</provider>
<uses-library />
</application>
</manifest>
0 0
- Android中的资源文件
- Android中的资源文件
- android中的资源文件
- android中的资源,资源与xml文件
- android中加载assets中的资源文件
- 编译android源码中的资源文件
- 编译android源码中的资源文件
- android中加载assets中的资源文件
- Android加载APK中的资源文件
- 编译android源码中的资源文件
- Android 加载其他Apk中的资源文件
- Android 上传资源文件中的图片
- vb中的资源文件
- 读取资源中的文件
- Android资源文件在配置文件中的使用与java代码对资源文件的操作
- Android 资源文件中的符号含义与说明
- Android 调用 资源目录下xml文件中的属性
- 提取android apk文件中的dat格式的图片资源
- pager-taglib分页中文乱码
- linux 查找大目录和大文件
- jQuery 获取对象的方法介绍
- 《安卓》一个按钮实现全选和全不选
- Redis
- android中的资源文件
- 刷牛客网的知识点整理-C++【持续更新...】
- 数据在编程的概念
- Spring之AOP专题报道(自己总结版)
- 用户空间的spi驱动
- vmware workstation的Host-only是不支持混杂模式的
- 安卓学习中Selector改变背景和文字颜色的笔记
- tomcat 配置虚拟站点
- 199_让PieChart出来之后动画