xamarin android pdf,Xamarin 中的Android资源及使用.pdf

Xamarin 中的Android资源及使用

Xamarin 中的Android 资源及使用

本文介绍Xamarin Android 中的Android 资源概念,以及如何使用资源。

讨论如何使用资源实现应用程序 地化,多种设备支持如各种屏幕大小

和密度。

This article introduces the concept of Android resources in

Xamarin.Android and will document how to use them. It covers how to use

resources in your Android application to support application localization,

and multiple devices including varying screen sizes and densities.

概述Overview

很少有Android 应用程序只包含源码。通常还有很多组成应用程序的文件:视频、图像、音

频文件等等。总体上说,非源码文件都是资源,在生成过程和打包APK 的时候与源码一起

编辑,并同时安装到设备:

An Android application is seldom just source code. There are often many other files that make up

an application: video, images, and audio files just to name a few. Collectively, these non-source

code files are referred to as resources and are compiled (along with the source code) during the

build process and packaged as an APK for distribution and installation onto devices:

资源为Android 应用程序提供各种优势:

代码隔离 将代码与图像、字符、菜单、动画、颜色等隔离开。比如可以方便的 地化。

多设备部署 无需修改代码就可以简单的实现不同设备的配置支持。

编译时检查 资源是静态的,可编译到应用程序中。这样就可以在编译的时候检查资源,修

正错误,否则在运行时很难定位和修改错误。

当新创建一个Xamarin Android 项目,会创建一个叫做Resources 的目录,同时还有很多子

目录:

Resources offer several advantages to an Android application:

Code-Separation - Separates source code from images, strings, menus, animations, colors, etc. As

such resources can help considerably when localizing.

Target multiple devices –Provides simpler support of different device configurations without

code changes.

Compile-time Checking - Resources are static and compiled into the application. This allows the

usage of the resources to be checked at compile time, when it will be easy to catch and correct the

mistakes, as opposed to run-time when it is more difficult to locate and costly to correct.

When a new Xamarin.Android proj ect is started, a special directory called Resources is created,

along with some subdirectories:

上图所示,应用程序资源按类型组织到各个子目录中:图像放在drawable 目录;控件放在

layout 目录等等。

在Xamarin Android 应用程序中有两种方式访问这些资源:使用代码或声明式XML 。

这些资源叫做默认资源可用于所有设备,除非指定了设备匹配

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值