Facebook Twitter LinkedIn E-mail
magnify
Home 2011 四月

Android ApiDemos示例解析(4):App->Activity->Custom Dialog

App->Activity->Custom Dialog 例子使用Activity 来实现自定义对话框。 类CustomDialogActivity本身无任何特别之处。关键的一点是其在AndroidManifest.xml中的定义:

<activity android:name=”.app.CustomDialogActivity”
android:label=”@string/activity_custom_dialog”
android:theme=”@style/Theme.CustomDialog“>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.SAMPLE_CODE” />
</intent-filter>
</activity>

CustomDialogActivity使用了CustomDialog 风格(Theme)。

Android应用可以使用自定义的界面风格(Theme),Theme 为一组相关的Style定义,可以应用于某个Activity或是整个Application。使用Theme的一个好处是可以为整个应用定义统一的界面风格(统一的背景色,字体等)。

定义Theme 和定义Style一样, 必须定义在/res/values子目录下,根元素名为resources, Theme 和Style的区别在于Theme应用于Activity和Application而 Style应用于单个的View。 其定义方法是一致的。Style 定义支持 Inheritance, 也就是在定义新风格时可以基于系统定义的风格或是之前定义的风格:

Theme.CustomDialog 定义就是基于Android的Dialog风格(parent)而只修改的WindowsBackground属性,使用了褐色背景。

<style name=”Theme.CustomDialog” parent=”android:style/Theme.Dialog”>
<item name=”android:windowBackground”>@drawable/filled_box</item>
</style>

 

Android ApiDemos示例解析(3): App->Activity->Animation

App->Activity->Animation 示例用于演示不同Activity切换时动态效果。例子中定义了两种动画效果,渐变Fade In, 新出现的Activity由浅入深逐渐显示,放大效果Zoom ,新出现的Activity由小及大逐渐显示。

Android 中 Animation 资源可以分为两种:

  • Tween Animation  对单个图像进行各种变换(缩放,平移,旋转等)来实现动画。
  • Frame Animation 由一组图像顺序显示显示动画。

Animation 中使用的是Tween Animation, 使用的资源为R.anim.fade, R.anim.hold,R.anim.zoom_enter, R.anim.zoom_exit。

其中R.anim.fade, R.anim.zoom_enter分别为Fade In 和 Zoom动画资源。其定义为

fade.xml

<alpha xmlns:android=”http://schemas.android.com/apk/res/android”
android:interpolator=”@android:anim/accelerate_interpolator”
android:fromAlpha=”0.0″ android:toAlpha=”1.0″
android:duration=”@android:integer/config_longAnimTime” />

zoom_center.xml

<set xmlns:android=”http://schemas.android.com/apk/res/android”
android:interpolator=”@android:anim/decelerate_interpolator”>
<scale android:fromXScale=”2.0″ android:toXScale=”1.0″
android:fromYScale=”2.0″ android:toYScale=”1.0″
android:pivotX=”50%p” android:pivotY=”50%p”
android:duration=”@android:integer/config_mediumAnimTime” />
</set>

tween animation 资源定义的格式如下:

<?xml version=”1.0″ encoding=”utf-8″?>
<set xmlns:android=”http://schemas.android.com/apk/res/android”
android:interpolator=”@[package:]anim/interpolator_resource”
android:shareInterpolator=[ ” true ” false “>
<alpha
android:fromAlpha=”float”
android:toAlpha=”float” />
<scale
android:fromXScale=”float”
android:toXScale=”float”
android:fromYScale=”float”
android:toYScale=”float”
android:pivotX=”float”
android:pivotY=”float” />
<translate
android:fromXDelta=”float”
android:toXDelta=”float”
android:fromYDelta=”float”
android:toYDelta=”float” />
<rotate
android:fromDegrees=”float”
android:toDegrees=”float”
android:pivotX=”float”
android:pivotY=”float” />
<set> …
</set>
</set>

<set> 为其它animation类型<alpha>,<scale>,<translate>和<rotate>或其它<set>的容器。

android:interpolator 为Interpolator资源ID,Interpolator定义了动画的变化速率,动画的各帧的显示可以加速,减速,重复显示。

android:shareInterpolator 如果想为<set>中的各个子动画定义共享interpolator,shareInterpolator 则设为true.

<alpha> 定义Fade in ,Fade out 动画,其对应的Android类AlphaAnimation,参数由fromAlpha,toAlpha定义。

<scale>定义缩放动画,其对应的Android类为ScaleAnimation,参数由fromXScale,toXScale,fromYScale,toYScale,pivotX,pivotY定义,pivotX,pivotY定义了缩放时的中心。

<translate>定义平移动画,其对应的Android类为TranslateAnimation,参数由fromXDelta,toXDelta,fromYDelta,toYDelta定义。

<rotate>定义选择动画,其对应的Android类RotateAnimation,参数由fromDegrees,toDegrees,pivotX,pivotY, pivotX,pivotY定义选择中心。

Animation中的Fade In和Zoom In按钮的事件处理代码:

<br />
private OnClickListener mFadeListener = new OnClickListener() {<br />
 public void onClick(View v) {<br />
 // Request the next activity transition (here starting a new one).<br />
 startActivity(new Intent(Animation.this, Controls1.class));<br />
 // Supply a custom animation.  This one will just fade the new<br />
 // activity on top.  Note that we need to also supply an animation<br />
 // (here just doing nothing for the same amount of time) for the<br />
 // old activity to prevent it from going away too soon.<br />
 overridePendingTransition(R.anim.fade, R.anim.hold);<br />
 }<br />
};</p>
<p>private OnClickListener mZoomListener = new OnClickListener() {<br />
 public void onClick(View v) {<br />
 // Request the next activity transition (here starting a new one).<br />
 startActivity(new Intent(Animation.this, Controls1.class));<br />
 // This is a more complicated animation, involving transformations<br />
 // on both this (exit) and the new (enter) activity.  Note how for<br />
 // the duration of the animation we force the exiting activity<br />
 // to be Z-ordered on top (even though it really isn't) to achieve<br />
 // the effect we want.<br />
 overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);<br />
 }<br />
};<br />

从代码可以看到Activity Animation到其它Activity Controls1 切换的动画使用overridePendingTransition 来定义,函数overridePendingTransition(int enterAnim, int exitAnim) 必须定义在StartActivity(Intent)或是 Activity.finish()之后来定义两个Activity切换时的动画,enterAnim 为新Activity出现时动画效果,exitAnim则定义了当前Activity退出时动画效果。

 

Android ApiDemos示例解析(2): SimpleAdapter,ListActivity,PackageManager

创建好ApiDemo项目后,就可以逐个示例的来分析代码,这里假定读者已对Android开发有些了解或是读过Android简明开发教程

首先是看ApiDemo的主Activity: com.example.android.apis.ApiDemos ,这个主Activity为ListActivity的子类,主要用来列出ApiDemos中的200多个实例,实例采取分类层次显示。

在ApiDemos 的 onCreate()中代码:

setListAdapter(new SimpleAdapter(this, getData(path),
 android.R.layout.simple_list_item_1, new String[] { "title" },
 new int[] { android.R.id.text1 }));

SimpleAdatper 作为数据源 getData(path) 与 UI ListActivity 之间的桥梁,它的构造函数如下:

SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)

我们知道ListActivity可以用来显示一个列表,在使用SimpleAdapter时可以借用二维表来更好的理解。 SimpleAdapter的数据源data 类型为List<? extends Map<String, ?>> List 中每一项为一个Map对象,相当于二维表中一行,这一行可以有多列,每列可以有个名字,为Map<String,?> string ,相当于表的列名:


ApiDemos中每条记录只显示一列”title”。 android.R.layout.simple_list_item_1 为用来显示每条记录的Layout资源id, ListActivity允许使用自定义Layout ,这里使用了Android系统资源,simple_list_item_1由一个TextView构成,其id为text1.

new String[] { “title” } 为需要显示的列表的数组,ApiDemos只显示一列“title”,如果有多列:则可以为new String[] { “title”,”field1”,”field2”,”field3” }。

new int[] { android.R.id.text1 }则指定使用 android.R.layout.simple_list_item_1 中 id 为text1的 TextView 来显示 “title” 列。 如果有多列,Layout可以定义多个View (不一定都为TextView) ,然后为每列指定显示的View的id。

再来看看getData(path)是如何定义的,protected List getData(String prefix) 返回一个列表

protected List getData(String prefix) {
List<Map> myData = new ArrayList<Map>();

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_SAMPLE_CODE);

PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);

... ...
for (int i = 0; i < len; i++) {
...
if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
addItem(myData, nextLabel, activityIntent(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name));
} else {
if (entries.get(nextLabel) == null) {
addItem(myData, nextLabel,
browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
entries.put(nextLabel, true);
}
}
}
}

Collections.sort(myData, sDisplayNameComparator);

return myData;
}

它通过PackageManager 从 AndroidManifest.xml中读取所以Intent-Filter含有:Intent.ACTION_MAIN和Intent.CATEGORY_SAMPLE_CODE所有Activity信息。前面说过200多个示例根据其功能分类,比如 Hello World示例它的Label为

App/Activity/<b>Hello <i>World</i></b>,

表是它的分类为分类App下Activity子类。getData(String prefix)根据每个Activity的Label属性和当前层次(prefix)来决定当前列表中某项为叶子列表项,还是分类列表项,如果是叶子列表项,则添加为activityIntent,当用户点击改列表项时则会触发该示例。若是分类列表项,则添加为browseIntent,browseIntent还是触发ApiDemos Activity,但Intent带有Extra信息,表示需要显示改分类下的子类:

Intent result = new Intent();
result.setClass(this, ApiDemos.class);
result.putExtra("com.example.android.apis.Path", path);

此时如果用户点击改节点列表项,则会进入还分类下级目录。

protected void addItem(List<Map> data, String name, Intent intent) {
Map<String, Object> temp = new HashMap<String, Object>();
temp.put("title", name);
temp.put("intent", intent);
data.add(temp);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Map map = (Map) l.getItemAtPosition(position);

Intent intent = (Intent) map.get("intent");
startActivity(intent);
}

addItem 给返回的List中添加一项,每个记录含两列 :”title”,”intent” ,其中只显示”title”列,如果想要显示”intent”列的信息,就不能使用android.R.layout.simple_list_item_1 了,这时可以另外定义一个Layout 来显示多列数据。 intent可以为触发示例,如”Hello World”或是下级示例列表,此时触发的Activity还是ApiDemos。
此外,ApiDemo还定义了ApiDemosApplication做为Application的子类,如果需要在多个Activity共享一些数据,可以定义在Application中。如果使用了自定义的Application,别忘了修改AndroidManifest.xml ,如下:

<application android:name=”ApiDemosApplication”
android:label=”@string/activity_sample_code”
android:icon=”@drawable/app_sample_code” >

</application>

 

Android ApiDemos示例解析(1):创建ApiDemo示例

Android SDK中带有很多例子,其中ApiDemo详细介绍了Android平台主要API,分成了

  • App
  • Content
  • Graphics
  • Media
  • OS
  • Text
  • Views

几个大类,每个大类又分为几个小类,一共大约有200多个实例,涵盖了Android OS API的各个方面:下面是所有示例的列表:

App/Activity/Animation
App/Activity/Custom Dialog
App/Activity/Custom Title
App/Activity/Dialog
App/Activity/Forwarding
App/Activity/Hello World
App/Activity/Persistent State
App/Activity/QuickContactsDemo
App/Activity/Receive Result
App/Activity/Redirection
App/Activity/Reorder Activities
App/Activity/Save & Restore State
App/Activity/SetWallpaper
App/Activity/Translucent
App/Activity/Translucent Blur
App/Activity/Wallpaper
App/Alarm/Alarm Controller
App/Alarm/Alarm Service
App/Device Admin
App/Dialog
App/Intents
App/Launcher Shortcuts
App/Menu/Inflate from XML
App/Notification/IncomingMessage
App/Notification/Notifying Service Controller
App/Notification/NotifyWithText
App/Notification/Status Bar
App/Preferences/1. Preferences from XML
App/Preferences/2. Launching preferences
App/Preferences/3. Preference dependencies
App/Preferences/4. Default values
App/Preferences/5. Preferences from code
App/Preferences/6. Advanced preferences
App/Search/Invoke Search
App/Search/Query Search Results
App/Service/Foreground Service Controller
App/Service/Local Service Binding
App/Service/Local Service Controller
App/Service/Messenger Service
App/Service/Remote Service Binding
App/Service/Remote Service Controller
App/Service/Service Start Arguments Controller
App/Text-To-Speech
App/Voice Recognition
Content/Assets/Read Asset
Content/Resources/Resources
Content/Resources/Styled Text
Content/Storage/External Storage
Graphics/AlphaBitmap
Graphics/AnimateDrawables
Graphics/Arcs
Graphics/BitmapDecode
Graphics/BitmapMesh
Graphics/BitmapPixels
Graphics/CameraPreview
Graphics/Clipping
Graphics/ColorFilters
Graphics/ColorMatrix
Graphics/Compass
Graphics/CreateBitmap
Graphics/Density
Graphics/Drawable/GradientDrawable
Graphics/Drawable/ShapeDrawable
Graphics/FingerPaint
Graphics/Layers
Graphics/MeasureText
Graphics/OpenGL ES/Compressed Texture
Graphics/OpenGL ES/Cube Map
Graphics/OpenGL ES/Frame Buffer Object
Graphics/OpenGL ES/GLSurfaceView
Graphics/OpenGL ES/Kube
Graphics/OpenGL ES/Matrix Palette Skinning
Graphics/OpenGL ES/OpenGL ES 2.0
Graphics/OpenGL ES/Sprite Text
Graphics/OpenGL ES/Textured Triangle
Graphics/OpenGL ES/Touch Rotate
Graphics/OpenGL ES/Translucent GLSurfaceView
Graphics/PathEffects
Graphics/PathFillTypes
Graphics/Patterns
Graphics/Pictures
Graphics/Points
Graphics/PolyToPoly
Graphics/PurgeableBitmap/NonPurgeable
Graphics/PurgeableBitmap/Purgeable
Graphics/Regions
Graphics/RoundRects
Graphics/ScaleToFit
Graphics/SensorTest
Graphics/SurfaceView Overlay
Graphics/Sweep
Graphics/Text Align
Graphics/Touch Paint
Graphics/Typefaces
Graphics/UnicodeChart
Graphics/Vertices
Graphics/Xfermodes
Media/MediaPlayer
Media/VideoView
OS/Morse Code
OS/Sensors
OS/SMS Messaging
Text/Linkify
Text/LogTextBox
Text/Marquee
Views/Animation/3D Transition
Views/Animation/Interpolators
Views/Animation/Push
Views/Animation/Shake
Views/Auto Complete/1. Screen Top
Views/Auto Complete/2. Screen Bottom
Views/Auto Complete/3. Scroll
Views/Auto Complete/4. Contacts
Views/Auto Complete/5. Contacts with Hint
Views/Auto Complete/6. Multiple items
Views/Buttons
Views/Chronometer
Views/Controls/1. Light Theme
Views/Controls/2. Default Theme
Views/Custom
Views/Date Widgets/1. Dialog
Views/Date Widgets/2. Inline
Views/Expandable Lists/1. Custom Adapter
Views/Expandable Lists/2. Cursor (People)
Views/Expandable Lists/3. Simple Adapter
Views/Focus/1. Vertical
Views/Focus/2. Horizontal
Views/Focus/3. Circular
Views/Focus/4. Internal Selection
Views/Gallery/1. Photos
Views/Gallery/2. People
Views/Grid/1. Icon Grid
Views/Grid/2. Photo Grid
Views/ImageButton
Views/ImageSwitcher
Views/ImageView
Views/Layout Animation/1. Grid Fade
Views/Layout Animation/2. List Cascade
Views/Layout Animation/3. Reverse Order
Views/Layout Animation/4. Randomize
Views/Layout Animation/5. Grid Direction
Views/Layout Animation/6. Wave Scale
Views/Layout Animation/7. Nested Animations
Views/Layouts/Baseline/1. Top
Views/Layouts/Baseline/2. Bottom
Views/Layouts/Baseline/3. Center
Views/Layouts/Baseline/4. Everywhere
Views/Layouts/Baseline/5. Multi-line
Views/Layouts/Baseline/6. Relative
Views/Layouts/Baseline/Nested Example 1
Views/Layouts/Baseline/Nested Example 2
Views/Layouts/Baseline/Nested Example 3
Views/Layouts/LinearLayout/1. Vertical
Views/Layouts/LinearLayout/10. Background Image
Views/Layouts/LinearLayout/2. Vertical (Fill Screen)
Views/Layouts/LinearLayout/3. Vertical (Padded)
Views/Layouts/LinearLayout/4. Horizontal
Views/Layouts/LinearLayout/5. Simple Form
Views/Layouts/LinearLayout/6. Uniform Size
Views/Layouts/LinearLayout/7. Fill Parent
Views/Layouts/LinearLayout/8. Gravity
Views/Layouts/LinearLayout/9. Layout Weight
Views/Layouts/RelativeLayout/1. Vertical
Views/Layouts/RelativeLayout/2. Simple Form
Views/Layouts/ScrollView/1. Short
Views/Layouts/ScrollView/2. Long
Views/Layouts/ScrollView/3. Internal Selection
Views/Layouts/TableLayout/01. Basic
Views/Layouts/TableLayout/02. Empty Cells
Views/Layouts/TableLayout/03. Long Content
Views/Layouts/TableLayout/04. Stretchable
Views/Layouts/TableLayout/05. Spanning and Stretchable
Views/Layouts/TableLayout/06. More Spanning and Stretchable
Views/Layouts/TableLayout/07. Column Collapse
Views/Layouts/TableLayout/08. Toggle Stretch
Views/Layouts/TableLayout/09. Toggle Shrink
Views/Layouts/TableLayout/10. Simple Form
Views/Layouts/TableLayout/11. Gravity
Views/Layouts/TableLayout/12. Cell Spanning
Views/Lists/1. Array
Views/Lists/10. Single choice list
Views/Lists/11. Multiple choice list
Views/Lists/12. Transcript
Views/Lists/13. Slow Adapter
Views/Lists/14. Efficient Adapter
Views/Lists/2. Cursor (People)
Views/Lists/3. Cursor (Phones)
Views/Lists/4. ListAdapter
Views/Lists/5. Separators
Views/Lists/6. ListAdapter Collapsed
Views/Lists/7. Cursor (Phones)
Views/Lists/8. Photos
Views/Lists/9. Array (Overlay)
Views/Progress Bar/1. Incremental
Views/Progress Bar/2. Smooth
Views/Progress Bar/3. Dialogs
Views/Progress Bar/4. In Title Bar
Views/Radio Group
Views/Rating Bar
Views/ScrollBars/1. Basic
Views/ScrollBars/2. Fancy
Views/ScrollBars/3. Style
Views/Seek Bar
Views/Spinner
Views/Tabs/Content By Factory
Views/Tabs/Content By Id
Views/Tabs/Content By Intent
Views/TextSwitcher
Views/Visibility
Views/WebView

将逐个介绍每个示例中涉及到的知识及相关类的用法.

首先是使用Eclipse创建一个ApiDemo示例:File ->New Android Project 选择Create project from existing sample (不同Android版本有对应的ApiDemo示例)。

App/Activity/Animation
App/Activity/Custom Dialog
App/Activity/Custom Title
App/Activity/Dialog
App/Activity/Forwarding
App/Activity/Hello World
App/Activity/Persistent State
App/Activity/QuickContactsDemo
App/Activity/Receive Result
App/Activity/Redirection
App/Activity/Reorder Activities
App/Activity/Save & Restore State
App/Activity/SetWallpaper
App/Activity/Translucent
App/Activity/Translucent Blur
App/Activity/Wallpaper
App/Alarm/Alarm Controller
App/Alarm/Alarm Service
App/Device Admin
App/Dialog
App/Intents
App/Launcher Shortcuts
App/Menu/Inflate from XML
App/Notification/IncomingMessage
App/Notification/Notifying Service Controller
App/Notification/NotifyWithText
App/Notification/Status Bar
App/Preferences/1. Preferences from XML
App/Preferences/2. Launching preferences
App/Preferences/3. Preference dependencies
App/Preferences/4. Default values
App/Preferences/5. Preferences from code
App/Preferences/6. Advanced preferences
App/Search/Invoke Search
App/Search/Query Search Results
App/Service/Foreground Service Controller
App/Service/Local Service Binding
App/Service/Local Service Controller
App/Service/Messenger Service
App/Service/Remote Service Binding
App/Service/Remote Service Controller
App/Service/Service Start Arguments Controller
App/Text-To-Speech
App/Voice Recognition
Content/Assets/Read Asset
Content/Resources/Resources
Content/Resources/Styled Text
Content/Storage/External Storage
Graphics/AlphaBitmap
Graphics/AnimateDrawables
Graphics/Arcs
Graphics/BitmapDecode
Graphics/BitmapMesh
Graphics/BitmapPixels
Graphics/CameraPreview
Graphics/Clipping
Graphics/ColorFilters
Graphics/ColorMatrix
Graphics/Compass
Graphics/CreateBitmap
Graphics/Density
Graphics/Drawable/GradientDrawable
Graphics/Drawable/ShapeDrawable
Graphics/FingerPaint
Graphics/Layers
Graphics/MeasureText
Graphics/OpenGL ES/Compressed Texture
Graphics/OpenGL ES/Cube Map
Graphics/OpenGL ES/Frame Buffer Object
Graphics/OpenGL ES/GLSurfaceView
Graphics/OpenGL ES/Kube
Graphics/OpenGL ES/Matrix Palette Skinning
Graphics/OpenGL ES/OpenGL ES 2.0
Graphics/OpenGL ES/Sprite Text
Graphics/OpenGL ES/Textured Triangle
Graphics/OpenGL ES/Touch Rotate
Graphics/OpenGL ES/Translucent GLSurfaceView
Graphics/PathEffects
Graphics/PathFillTypes
Graphics/Patterns
Graphics/Pictures
Graphics/Points
Graphics/PolyToPoly
Graphics/PurgeableBitmap/NonPurgeable
Graphics/PurgeableBitmap/Purgeable
Graphics/Regions
Graphics/RoundRects
Graphics/ScaleToFit
Graphics/SensorTest
Graphics/SurfaceView Overlay
Graphics/Sweep
Graphics/Text Align
Graphics/Touch Paint
Graphics/Typefaces
Graphics/UnicodeChart
Graphics/Vertices
Graphics/Xfermodes
Media/MediaPlayer
Media/VideoView
OS/Morse Code
OS/Sensors
OS/SMS Messaging
Text/Linkify
Text/LogTextBox
Text/Marquee
Views/Animation/3D Transition
Views/Animation/Interpolators
Views/Animation/Push
Views/Animation/Shake
Views/Auto Complete/1. Screen Top
Views/Auto Complete/2. Screen Bottom
Views/Auto Complete/3. Scroll
Views/Auto Complete/4. Contacts
Views/Auto Complete/5. Contacts with Hint
Views/Auto Complete/6. Multiple items
Views/Buttons
Views/Chronometer
Views/Controls/1. Light Theme
Views/Controls/2. Default Theme
Views/Custom
Views/Date Widgets/1. Dialog
Views/Date Widgets/2. Inline
Views/Expandable Lists/1. Custom Adapter
Views/Expandable Lists/2. Cursor (People)
Views/Expandable Lists/3. Simple Adapter
Views/Focus/1. Vertical
Views/Focus/2. Horizontal
Views/Focus/3. Circular
Views/Focus/4. Internal Selection
Views/Gallery/1. Photos
Views/Gallery/2. People
Views/Grid/1. Icon Grid
Views/Grid/2. Photo Grid
Views/ImageButton
Views/ImageSwitcher
Views/ImageView
Views/Layout Animation/1. Grid Fade
Views/Layout Animation/2. List Cascade
Views/Layout Animation/3. Reverse Order
Views/Layout Animation/4. Randomize
Views/Layout Animation/5. Grid Direction
Views/Layout Animation/6. Wave Scale
Views/Layout Animation/7. Nested Animations
Views/Layouts/Baseline/1. Top
Views/Layouts/Baseline/2. Bottom
Views/Layouts/Baseline/3. Center
Views/Layouts/Baseline/4. Everywhere
Views/Layouts/Baseline/5. Multi-line
Views/Layouts/Baseline/6. Relative
Views/Layouts/Baseline/Nested Example 1
Views/Layouts/Baseline/Nested Example 2
Views/Layouts/Baseline/Nested Example 3
Views/Layouts/LinearLayout/1. Vertical
Views/Layouts/LinearLayout/10. Background Image
Views/Layouts/LinearLayout/2. Vertical (Fill Screen)
Views/Layouts/LinearLayout/3. Vertical (Padded)
Views/Layouts/LinearLayout/4. Horizontal
Views/Layouts/LinearLayout/5. Simple Form
Views/Layouts/LinearLayout/6. Uniform Size
Views/Layouts/LinearLayout/7. Fill Parent
Views/Layouts/LinearLayout/8. Gravity
Views/Layouts/LinearLayout/9. Layout Weight
Views/Layouts/RelativeLayout/1. Vertical
Views/Layouts/RelativeLayout/2. Simple Form
Views/Layouts/ScrollView/1. Short
Views/Layouts/ScrollView/2. Long
Views/Layouts/ScrollView/3. Internal Selection
Views/Layouts/TableLayout/01. Basic
Views/Layouts/TableLayout/02. Empty Cells
Views/Layouts/TableLayout/03. Long Content
Views/Layouts/TableLayout/04. Stretchable
Views/Layouts/TableLayout/05. Spanning and Stretchable
Views/Layouts/TableLayout/06. More Spanning and Stretchable
Views/Layouts/TableLayout/07. Column Collapse
Views/Layouts/TableLayout/08. Toggle Stretch
Views/Layouts/TableLayout/09. Toggle Shrink
Views/Layouts/TableLayout/10. Simple Form
Views/Layouts/TableLayout/11. Gravity
Views/Layouts/TableLayout/12. Cell Spanning
Views/Lists/1. Array
Views/Lists/10. Single choice list
Views/Lists/11. Multiple choice list
Views/Lists/12. Transcript
Views/Lists/13. Slow Adapter
Views/Lists/14. Efficient Adapter
Views/Lists/2. Cursor (People)
Views/Lists/3. Cursor (Phones)
Views/Lists/4. ListAdapter
Views/Lists/5. Separators
Views/Lists/6. ListAdapter Collapsed
Views/Lists/7. Cursor (Phones)
Views/Lists/8. Photos
Views/Lists/9. Array (Overlay)
Views/Progress Bar/1. Incremental
Views/Progress Bar/2. Smooth
Views/Progress Bar/3. Dialogs
Views/Progress Bar/4. In Title Bar
Views/Radio Group
Views/Rating Bar
Views/ScrollBars/1. Basic
Views/ScrollBars/2. Fancy
Views/ScrollBars/3. Style
Views/Seek Bar
Views/Spinner
Views/Tabs/Content By Factory
Views/Tabs/Content By Id
Views/Tabs/Content By Intent
Views/TextSwitcher
Views/Visibility
Views/WebView
 

免费Java反编译工具decompiler

Decompiler下载

用法:
命令行运行:

usage

decompiler  xxx.class  反编译单个class文件
decompiler  directoryname   反编译该目录下所有.class文件,包括子目录。

log.txt 为日志文件

 

如何打开Android 打包文件 .apk 文件

在学习Android开发的过程中,常常想知道一些界面设计优良的应用是如何设计的。Android应用最后发布是以 .apk 文件提供的。那么如何在PC上打开这个 .apk文件呢? .apk 文件实际就是.zip 文件,可以使用WinZip ,WinRar 等来解压,一个简单的方法是把 .apk 后缀改成 .zip 文件。如果就可以使用WinZip解压开。

比如 Google Map 的 .apk 文件 解压后 有如下文件及目录:

res 为 Android应用中的资源文件,包括layout, drawable, values ,menus 等。

AndroidManifest.xml 为 Android应用的 Manifest文件。

class.dex  为 Java编译成Dalvik 代码(非Java code)。

.apk 打包后的 所以.xml 文件格式为binary XML 文件格式,可以使用AXMLPrinter2.jar

将二进制XML转回文本格式:

java -jar AXMLPrinter2.jar AndroidManifest.xml > AndroidManifest.xml.txt