随笔14

来源:互联网 发布:windows 远程桌面服务 编辑:程序博客网 时间:2024/05/17 21:49

     今天看了<Google Android SDK 开发范例大全 第二版> 4.10

     发现里面有个xml文件中有一个资源是 <declare-styleable>, 一开始不知道是啥东西, 看完章节还不是很懂.

赶紧上网查查, 发现这篇文章

declare-styleable, 自定义属性

写得很不错的文章.

 


 

 

      原来, 我们一般写的布局xml 文件, 需要

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="vertical"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
    >

    .............

    </LinearLayout>

 

  •  像 layout_width 这样的属性, 是在 platforms/android-7/data/res/values/attrs.xml 中配置的,
  •  并且为什么要写 xmlns:android="http://schemas.android.com/apk/res/android" 这个也清楚了.
  •  还有 android 的控件 View 的构造方法之一, public View(Context context, AttributeSet attrs)

          第二个参数 AttributeSet 能搞懂一些了, 其源代码

  • 同时解释了为什么在布局xml 文件中, 我们可以添加属性 layout_width, 但是后台的代码没有 setLayoutWidth() 方法, 虽然有其他方法 setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 能达到效果,  但是对于习惯getXX() 和 setXX() 的人来说..... 唉! 不说了.
  • 类似 orientation 属性, 后台代码是没有 setOrientation() 方法的, 本人也不知道实现其效果的后台代码方法. 对于动态添加控件的人来说, 这是无比郁闷的事情!!!!!!!


原创粉丝点击