资源的引用

在Android开发中对资源的引用是很重要的内容,看一个Android工程结构的好与坏,其实看看工程结构的资源文件的相互关系就大概可以看出来了,个人觉得学习好Android,资源文件是很重要的部分,这里讲的都是些入门级别的知识点,耐下心思看哦,呵呵。
1, 三种资源文件形式。资源文件之间的相互引用自然是基础的基础,三种形式(android:xxx/yyy,@xxxx/yyy,?xxx)的区别要彻底地弄明白。
2, 资源文件的属性命名。资源文件属性的命名(其实大部分是id名字,也有其它的,这里不再累赘)对于初学者可能不太会在意,其实是很重要的部分,它其实也就是一些我们预先定义好的变量,能不在乎吗,这些变量会在自动生成映射类R.java中生成一些静态索引值,帮助Android快速定位,命名说白了,也是要求我们做到望名知意(最好包括类型)。
3, 每个工程都会有对应的一个AndroidManifest.xml文件,这个文件要注意的是一些权限的表示属性,如:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
看命名就知道是针对什么做权限限制,所以初学者要注意了,在你的程序运行的时候报SecurityException的时候要看看你的程序是否涉及到限制操作,呵呵。这些在android.Manifest.permission里面,大家自己看可能会更好,自己学习的能力很重要哦,要不然你做的不可能是前沿的东西啦。
4, 自己定义类的引用。怎么定义、怎么使用,可以参考ApiDemo里面的经典实例:com.example.android.apis.view.LableView.java 。这也是很重哦,因为在我们开发的过程中,Android提供的UI肯定不能满足我们的要求,这样你就得自己写新的UI类,我在开发中就遇到很多这样的问题。如,Android现有的TabHost,在TabSpec多的时候你就感觉出TabHost英雄无用武之地啦,这样就得自己写了。
写自己的Android Components

上面的第四点已经提到了一下,学会写自己的控件的重要性。在Android里面,提供了丰富的类库,如何使用好也是值得探讨的问题。当然这里说的也是api里面说的,这里说的主要是我在学习的过程中认为很重要的方面.
主要把界面布局类:LinearLayout和FrameLayout弄懂简单的开发就够了,再深入一点就要把ViewManager及其子类弄清楚了。
其中,LinearLayout垂直和水平两种,他们之间可以相互嵌套,嵌套时候要注意高和宽的属性,如。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.srk.study"
android:id="@+id/screen" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background" android:focusable="true"
android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="65dip"
android:background="@drawable/background"
android:orientation="horizontal">
<com.srk.study.model.TitleView android:id="@+id/titleView"
android:layout_width="280dip" android:layout_height="65dip"
android:paddingLeft="5dip" android:paddingTop="10dip"
app:[email protected]/whiteColor app:[email protected]/blackColor
app:titleSize="15dip" />
<com.srk.study.model.ConnectView android:id="@+id/connectView"
android:layout_height="65dip"
android:layout_width="40dip" app.startX="280dip" />
</LinearLayout>
<!-- ############# Body ############ -->
<ListView android:id="@+id/bodyListView" android:layout_width="fill_parent"
android:paddingTop="3dip" android:layout_height="wrap_content"
android:layout_weight="1.0"
android:persistentDrawingCache="animation|scrolling"
android:scrollbars="vertical" android:focusable="true"
android:scrollbarSize="12dip" />
</LinearLayout>
以上的配置文件是我学习过程的小练习,在这里秀一下,哈哈,记得在去年刚毕业的时候,特别爱学习,什么都想弄弄,在去年一年的时光中,每天都过得很充实,也许那就是年轻的标志吧,扯远了。今天就说这么多,有空分享点源代码出来。。。

更多相关文章

  1. Android中使用Pull解析器解析xml文件+进行简单的单元测试
  2. 非root下,如何将android中的数据库文件存放到外部存储并导出
  3. Android WebView加载https页面不能正常显示资源问题
  4. android 将app添加进入文件的打开方式
  5. android:scaleType="matrix"布局文件加载图片时候的显示方式
  6. Android读取sql文件并导入数据库
  7. Android音频处理——通过AudioRecord去保存PCM文件进行录制,播放,
  8. cocos2d-lua android解决启动时因为资源加载而黑屏的问题

随机推荐

  1. android:layout_alignParent 布局相对于
  2. Android之UI设计TextView属性
  3. Android(安卓)国际化(多语言)兼容8.0
  4. eclipse中开发Android出现问题解决记录和
  5. [Android]电话拨号器开发
  6. android图表收益曲线-MPAndroidChart
  7. Android中的常用控件之进度条(ProgressBar
  8. h5页面与Android原生页面交互
  9. Android之Adapter用法总结
  10. Android(安卓)开发实践 Lambda表达式的使