Android 开发的隐藏功能?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1619133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hidden features of Android development?
提问by Artem Russakovskii
I am surprised that there is no Android Hidden Featurespost yet in the Hidden Features seriesthat I've been tracking for a while now.
我很惊讶在我已经跟踪了一段时间的隐藏功能系列中还没有 Android隐藏功能帖子。
The Hidden Features series is great for people who are new to a certain language. It shows the ropes and certain valuable tricks, all in one place. I think it's a brilliant idea. Even experts sometimes find tricks they'd never heard about.
Hidden Features 系列非常适合刚接触某种语言的人。它在一个地方展示了绳索和某些有价值的技巧。我认为这是一个绝妙的主意。即使是专家有时也会发现他们从未听说过的技巧。
I am starting Android development and I'd love to hear about its hidden features, tips, tricks, and pitfalls.
我正在开始 Android 开发,我很想听听它的隐藏功能、提示、技巧和陷阱。
So, here goes: what are some hidden featuresof Android?
所以,这里有云:什么是一些隐藏的功能的安卓?
采纳答案by Reto Meier
Hopefully there aren't too many hidden, hidden features - but here's some of the less well known and non-intuitive features available for Android that will definitely make your life easier and your apps better.
希望没有太多隐藏的、隐藏的功能 - 但这里有一些鲜为人知和非直观的功能可用于 Android,它们肯定会让您的生活更轻松,您的应用程序更好。
- All the source code for the platform and all the non-Google native apps is available for you to browse, download, borrow, or steal from the Android Open Source project.
- Using the resources framework, creating localized versions of your app is as simple as adding a new annotated subfolder (Eg. values-fr) that contains an XML file with strings in a different language (Eg. French). Android will choose the right folder at runtime for you.
- The same resources framework lets you use alternate layouts for different hardware configurations, screen pixel densities, and input devices just by dropping them in named folder.
- Since Android 1.6, your app can produce results that will appear in the results from a homescreen Quick Search Box search. This is known as custom search suggestions.
- Using Intents and Intent Filtersyour apps can make and service anonymous requests for an action to be completed (Eg. The Where app can request a table booking from the Open Table app).
- They can request an unknown application to complete an action without needing to know which application(s) can fulfill that request
- Your app can fulfill requests from unknown apps to complete actions without needing to know which apps will make the requests. Play this right and you can create the 'default' Twitter app, or booking app, etc.
- Using Alarmsyou can set your app to complete tasks at predetermined times, even if your app isn't running.
- You can save a lot of battery life using the setInexactRepeatingmethod to schedule regular events (like server polling or updates). It will synchronize alarms from multiple apps to occur at the same time rather than adhoc.
- Using the Preferencesframework you can create settings screens for your apps in the same style as the system settings. You can even incorporate system settings screens (Eg. Security and Location) into your application's settings hierarchy.
- Using the AudioTrack and AudioRecordAPIs, you can stream audio data directly from and to the PCM audio buffers.
- 该平台的所有源代码和所有非 Google 原生应用程序都可供您浏览、下载、借用或窃取Android 开源项目。
- 使用资源框架,创建应用程序的本地化版本就像添加一个新的带注释的子文件夹(例如 values-fr)一样简单,该文件夹包含带有不同语言(例如法语)字符串的 XML 文件。Android 会在运行时为您选择正确的文件夹。
- 相同的资源框架允许您将不同的布局用于不同的硬件配置、屏幕像素密度和输入设备,只需将它们放在命名文件夹中即可。
- 从 Android 1.6 开始,您的应用可以生成将显示在主屏幕快速搜索框搜索结果中的结果。这称为自定义搜索建议。
- 使用Intents 和 Intent Filters,您的应用程序可以发出匿名请求并为要完成的操作提供服务(例如,Where 应用程序可以从 Open Table 应用程序请求餐桌预订)。
- 他们可以请求未知应用程序完成操作,而无需知道哪些应用程序可以满足该请求
- 您的应用程序可以满足来自未知应用程序的请求以完成操作,而无需知道哪些应用程序将发出请求。正确播放,您可以创建“默认”Twitter 应用程序或预订应用程序等。
- 使用闹钟,您可以将您的应用设置为在预定时间完成任务,即使您的应用没有运行。
- 您可以使用setInexactRepeating方法来安排常规事件(如服务器轮询或更新),从而节省大量电池寿命。它将同步来自多个应用程序的警报以同时发生而不是临时发生。
- 使用首选项框架,您可以以与系统设置相同的风格为您的应用程序创建设置屏幕。您甚至可以将系统设置屏幕(例如安全和位置)合并到应用程序的设置层次结构中。
- 使用AudioTrack 和 AudioRecordAPI,您可以将音频数据直接从 PCM 音频缓冲区传入或传向 PCM 音频缓冲区。
回答by jamesh
The tools in the /tools directoryof the SDK deserve a mention:
将在/ tools目录工具的SDK值得一提:
- our designer was particularly impressed with
draw9patch
which helped design stretchable buttons. He gave me assets from there, and I changed from a background colour to a 9-patch drawable and now we have a custom button, rounded corners, etc stretched to fit the text. ddms
, which is also integrated into the Eclipse plugin. It's immensely powerful, but I use it to take screenshots.adb
- interact with your device or emulator from the command line. I use this to follow the logs from my device in a terminal window on my desktop, though I have found it useful for installing and uninstalling apps which are misbehaving.sqlite3
- great for interacting with an installed database, and trying out queries.apkbuilder
,zipalign
,aapt
- great for running headless buildsmonkey
for fuzz-testing your app.
- 我们的设计师对它
draw9patch
帮助设计了可拉伸的按钮印象特别深刻。他从那里给了我资产,我从背景颜色更改为 9 补丁可绘制,现在我们有一个自定义按钮、圆角等拉伸以适应文本。 ddms
,它也集成到 Eclipse 插件中。它非常强大,但我用它来截取屏幕截图。adb
- 从命令行与您的设备或模拟器交互。我使用它在桌面终端窗口中跟踪设备中的日志,但我发现它对于安装和卸载行为不端的应用程序很有用。sqlite3
- 非常适合与已安装的数据库交互和尝试查询。apkbuilder
,zipalign
,aapt
- 非常适合运行无头构建monkey
用于模糊测试您的应用程序。
I would also single out the three Designing for Performance, Responsivenessand Seamlessness, but I'd also like to add a fourth Coding for (Battery) Life.
我还想挑出三个性能设计、响应性和无缝性,但我还想添加第四个编码(电池)寿命。
Although the Javadoc can be a little sparse at times, it helps no endto have the source right there for you to look at.
虽然Javadoc中有时可能是有点稀疏,它可以帮助没有尽头有源就在那里给你看。
It is also very useful to have plenty of sample apps written by Googlersto build, examine and then see how they did it.
拥有大量由 Google 员工编写的示例应用程序来构建、检查并查看他们是如何做到的,这也非常有用。
回答by Artem Russakovskii
I guess I'll start then.
我想我会开始。
A nice hidden feature I think is the Best Practices of the Android documentation. It lists plenty of great tips for designing responsive and fast apps.
我认为一个很好的隐藏功能是 Android 文档的最佳实践。它列出了许多用于设计响应式和快速应用程序的重要技巧。
Best Practicessections are:
最佳实践部分是:
- Supporting Multiple Screens (multiple sizes and resolutions)
- UI Guidelines
- Icon Design
- App Widget Design
- Activity and Task Design
- Menu Design
- Designing for Performance
- Designing for Responsiveness
- Designing for Seamlessness
- 支持多屏幕(多种尺寸和分辨率)
- 用户界面指南
- 图标设计
- 应用小部件设计
- 活动和任务设计
- 菜单设计
- 性能设计
- 响应性设计
- 无缝设计
Another hidden feature is that these docs are available offline as part of the SDK. At first I was loading up a few pages every day for my morning train ride but didn't need to do that anymore after I found them in the SDK directory.
另一个隐藏功能是这些文档作为 SDK 的一部分可离线使用。起初,我每天为早上的火车旅行加载几页,但在 SDK 目录中找到它们后就不再需要这样做了。
If you use Eclipse, you will notice that it doesn't format XML files very well and when it does, it's very inconsistent (sometimes it splits the attributes by new lines, sometimes it doesn't). To fix it, you can press Ctrl-Shift-F (auto-format). The rules Ctrl-Shift-F uses are in Window->Preferences->XML->XML Files->Editor.
如果您使用 Eclipse,您会注意到它不能很好地格式化 XML 文件,并且当它格式化时,它非常不一致(有时它会用新行拆分属性,有时不会)。要修复它,您可以按 Ctrl-Shift-F(自动格式化)。Ctrl-Shift-F 使用的规则在 Window->Preferences->XML->XML Files->Editor。
回答by Timmmm
Android supports XML <shape>
's which can be used as SVG-like drawables. Unfortunately there's no documentation for them. This is the best information I could find:
Android 支持 XML <shape>
,它可以用作类似 SVG 的可绘制对象。不幸的是,没有关于它们的文档。这是我能找到的最好的信息:
回答by dljava
Also with regard to best practices, you may want to check out Android coding style:
另外关于最佳实践,您可能需要查看 Android 编码风格:
http://source.android.com/source/code-style.html
http://source.android.com/source/code-style.html
as well as the eclipse code and imports formatters (android-formatting.xml, android.importorder) which are found in the platform source code under development/ide/eclipse
以及 eclipse 代码和导入格式化程序(android-formatting.xml、android.importorder),它们位于 development/ide/eclipse 下的平台源代码中
回答by Ivo van der Wijk
hierarchyviewerin /tools allows you to debug/analyze your view layout: padding, positioning, view hierarchy etc.
/tools 中的hierarchyviewer允许您调试/分析您的视图布局:填充、定位、视图层次结构等。
It saved me a lot of time a couple of times when trying to figure out why things are laid out the way they are.
在试图弄清楚为什么事情是这样布置的时候,它为我节省了很多时间。