转载请注明出处:http://blog.csdn.net/guxiao1201/article/details/40708775
Activity public boolean isChangingConfigurations ()
- 常用于屏幕方法改变时的逻辑处理,但我还没用到过,所以详细介绍还是挪步到
Activity.isChangingConfigurations()
Check to see whether this activity is in the process of being destroyed in order to be recreated with a new configuration. This is often used in onStop()
to determine whether the state needs to be cleaned up or will be passed on to the next instance of the activity via onRetainNonConfigurationInstance()
.
Returns
- If the activity is being torn down in order to be recreated with a new configuration, returns true; else returns false.
ViewTreeObserver
- 可以注册监听正在屏幕上显示的视图树中任何视图状态的变化,我经常用来视图初始化完成后获取某个控件的尺寸。
A view tree observer is used to register listeners that can be notified of global changes in the view tree. Such global events include, but are not limited to, layout of the whole tree, beginning of the drawing pass, touch mode change.... A ViewTreeObserver should never be instantiated by applications as it is provided by the views hierarchy. Refer to getViewTreeObserver()
for more information.
DatabaseUtils
- 一个包装了一系列数据库操作方法的工具类(不过我没用过,还是喜欢手动敲sql)
android:weightSum
- 如果想实现一个Button,宽度占据屏幕宽度的50%怎么办?代码动态计算?尝试结合使用android:weightSum和android:layout_weight吧。参考博客:合用weightSum属性和layout_weight属性
Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.
Must be a floating point value, such as "1.2
".
This may also be a reference to a resource (in the form "@[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type.
This corresponds to the global attribute resource symbol weightSum
.
android:duplicateParentState/android:addStatedFromChildren
- 使用这个属性来应对那些挑剔的UI再好不过了。之前还苦恼父控件和点击状态怎么和子控件同步,直到看到这个属性真实相见恨晚。但使用过程中需注意这两个属性只是传递点击状态而不会执行点击事件。参考博客:Android View与View之间的状态关联处理
When this attribute is set to true, the view gets its drawable state (focused, pressed, etc.) from its direct parent rather than from itself.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form "@[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type.
This corresponds to the global attribute resource symbol duplicateParentState
.
android:clipChildren
- 设置这个属性后子控件就可以在父控件的范围之外进行绘制了,编写动画时再也不用一层多余的FrameLayout。
Defines whether a child is limited to draw inside of its bounds or not. This is useful with animations that scale the size of the children to more than 100% for instance. In such a case, this property should be set to false to allow the children to draw outside of their bounds. The default value of this property is true.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form "@[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type.
This corresponds to the global attribute resource symbol clipChildren
.
Related Methods
android:fillViewport
- 当开发者需要设置一个内容不足以填充整个屏幕的ScrollView全屏时,设置fill_parent是不起作用的,那么使用这个属性吧。
Defines whether the scrollview should stretch its content to fill the viewport.
Must be a boolean value, either "true
" or "false
".
This may also be a reference to a resource (in the form "@[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type.
This corresponds to the global attribute resource symbol fillViewport
.
android:tileMode
- 用来设置Bitmap显示方式,有平铺、重复等。例如设置重复显示
<xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat"
>
backrepeat.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/repeatimg"
android:tileMode="repeat"
android:dither="true" />
Defines the tile mode. When the tile mode is enabled, the bitmap is repeated. Gravity is ignored when the tile mode is enabled. Default value is "disabled".
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
disabled | -1 | Do not tile the bitmap. This is the default value. |
clamp | 0 | Replicates the edge color. |
repeat | 1 | Repeats the bitmap in both direction. |
mirror | 2 | Repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam. |
This corresponds to the global attribute resource symbol tileMode
.
android:enterFadeDuration/android:exitFadeDuration
- 为selector设置渐变效果,示例:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:enterFadeDuration="500"
android:exitFadeDuration="500">
<item android:state_focused="true"
android:drawable="@color/press"/>
<item
android:state_pressed="true"
android:drawable="@color/press"/>
<item
android:drawable="@color/normal"/>
</selector>

Amount of time (in milliseconds) to fade out an old state drawable.
Must be an integer value, such as "100
".
This may also be a reference to a resource (in the form "@[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type.
android:scaleType
- 经常用到的设置图片在ImageView中的展示样式。参考示例请挪步:ImageView.ScaleType设置图解
Controls how the image should be resized or moved to match the size of this ImageView.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
matrix | 0 | |
fitXY | 1 | |
fitStart | 2 | |
fitCenter | 3 | |
fitEnd | 4 | |
center | 5 | |
centerCrop | 6 | |
centerInside | 7 |
This corresponds to the global attribute resource symbol scaleType
.
<merge>
- 在某些情况下可以优化UI结构,删除多余层级。但个人感觉使用情景有些局限。使用详情见:
Android Layout Tricks #3: Optimize by merging
参考资料: