ViewGroup Width/Height ,Padding/margin
FrameLayout gravity
LinearLayout Orientation/horizontal/vertical weight
RelativeLayout alignBaseline/(Left/Top/Right/Bottom) Start/End alignParent center Horizontal/Vertical/InParent below/above/toLeftOf/toRightOf/toStartOf/toEndOf
LinearLayout代码设置weight LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f);
linearLayout.setLayoutParams(lp); Android布局优化 (非常好的一篇文章) http://www.infoq.com/cn/articles/android-optimise-layout selector几种状态 state_pressed
state_focused
state_selected TextView常用属性 android:ellipsize="none"
android:singleLine="true"
android:textColor=""
android:textSize=""

一、RelativeLayout布局属性 与 include、merge简单总结

// 当前视图顶部,底部,左侧,右侧与其他视图间填充区域

[html] view plain copy print ?
  1. android:layout_marginTop
  2. android:layout_marginBottom
  3. android:layout_marginLeft
  4. android:layout_marginRight

java代码设置

[java] view plain copy print ?
  1. RelativeLayout.LayoutParamslayoutParams=newRelativeLayout.LayoutParams(
  2. LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
  3. //单位是px
  4. layoutParams.topMargin=66;
  5. layoutParams.bottomMargin=66;
  6. layoutParams.leftMargin=66;
  7. layoutParams.rightMargin=66;






// 当前视图内顶部,底部,左侧,右侧填充区域 (非RelativeLayout属性)

[html] view plain copy print ?
  1. android:paddingTop
  2. android:paddingBottom
  3. android:paddingLeft
  4. android:paddingRight



// 在指定ID视图上面,下面,左侧,右侧

[html] view plain copy print ?
  1. android:layout_above
  2. android:layout_below
  3. android:layout_toLeftOf
  4. android:layout_toRightOf


Java代码设置

[java] view plain copy print ?
  1. RelativeLayout.LayoutParamslayoutParams=newRelativeLayout.LayoutParams(
  2. LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
  3. layoutParams.addRule(RelativeLayout.ABOVE,R.id.viewId);
  4. layoutParams.addRule(RelativeLayout.BELOW,R.id.viewId);
  5. layoutParams.addRule(RelativeLayout.LEFT_OF,R.id.viewId);
  6. layoutParams.addRule(RelativeLayout.RIGHT_OF,R.id.viewId);






// 与制定ID视图baseLine,顶部,底部,左侧,右侧边缘对齐

[html] view plain copy print ?
  1. android:layout_alignBaseline
  2. android:layout_alignTop
  3. android:layout_alignBottom
  4. android:layout_alignLeft
  5. android:layout_alignRight

Java代码设置

[java] view plain copy print ?
  1. RelativeLayout.LayoutParamslayoutParams=newRelativeLayout.LayoutParams(
  2. LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
  3. layoutParams.addRule(RelativeLayout.ALIGN_BASELINE,R.id.viewId);
  4. layoutParams.addRule(RelativeLayout.ALIGN_TOP,R.id.viewId);
  5. layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM,R.id.viewId);
  6. layoutParams.addRule(RelativeLayout.ALIGN_LEFT,R.id.viewId);
  7. layoutParams.addRule(RelativeLayout.ALIGN_RIGHT,R.id.viewId);





// 与父视图顶部,底部,左侧,右侧边缘对齐

[html] view plain copy print ?
  1. android:layout_alignParentTop
  2. android:layout_alignParentBottom
  3. android:layout_alignParentLeft
  4. android:layout_alignParentRight


Java代码设置

[java] view plain copy print ?
  1. RelativeLayout.LayoutParamslayoutParams=newRelativeLayout.LayoutParams(
  2. LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
  3. layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
  4. layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  5. layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
  6. layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);







// 横向居中,纵向居中,针对与父视图剧中

[html] view plain copy print ?
  1. android:layout_centerHorizontal
  2. android:layout_centerVertical
  3. android:layout_centerInParent

Java代码设置

[java] view plain copy print ?
  1. RelativeLayout.LayoutParamslayoutParams=newRelativeLayout.LayoutParams(
  2. LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
  3. layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
  4. layoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
  5. layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);

** Include 与 mege标签

参考资料:

Re-using Layouts with <include/>

Romain Guy Android Layout Tricks #3: Optimize, Part 1

** ViewGroup相关配置

1.clipChildren

android:clipChildren setClipChildren(boolean)Defines whether a child is limited to draw inside of its bounds or not.
定义是否限制子视图在它的范围内进行绘制。默认是true

2.clipToPadding
android:clipToPadding setClipToPadding(boolean)Defines whether the ViewGroup will clip its drawing surface so as to exclude the padding area.
定义ViewGroup是否将剪切它的绘制界面并排除padding区域。默认是true

参考资料:

ViewGroup API

* 配置文件属性与Java代码方法对应 android:gravity
android:layout_gravity

android:layout_gravity="right"
lp.gravity = Gravity.RIGHT;
button.setGravity(Gravity.CENTER); * View属性,子视图与父控件perssed 等状态保持一致
xml配置: android:duplicateParentState 代码: setDuplicateParentStateEnabled * ViewGroup属性,父视图与子视图pressed状态保持一致 xml配置: android:addStatesFromChildren 代码: setAddStatesFromChildren

设置EditText光标位置

http://www.cnblogs.com/nanhuchongzi/archive/2012/04/17/2444451.html

**margin与padding的区别?

一个属于视图内,一个属于试图外 margin之后,如果视图隐藏,margin不会隐藏 因为margin是视图外的部分 padding会算如总宽吗? 会算入总宽 ** 动态修改宽高
view.getLayoutParams().width = widthValue;

Android进阶练习-改善布局性能
http://blog.csdn.net/tu_bingbing/article/details/8654990

**TextView 显示两行,其余用....替换
android:maxLines="2"
android:ellipsize="end"


values/ids.xml
<resources>
<item type="id" name="idname" />
</resources>
view.setId(R.id. idname);

***

布局XML Schema
有哪些属性,是在XML Schema定义,可以在http://www.w3school.com.cn/schema/schema_intro.asp了解Schema更多知识。
Android 布局XML Schema在什么地方? 查询补漏

布局在Java中的对应关系 TypeArray

原文地址:http://blog.csdn.net/love_world_/article/details/8426935

2013-12-29 添加gravity、layout_gravity、duplicateParentState

2014-04-10 添加布局XML Schema

更多相关文章

  1. android EditText设置不可写
  2. android 使用html5作布局文件: webview跟javascript交互
  3. android studio调试c/c++代码
  4. android“设置”里的版本号
  5. IM-A820L限制GSM,WCDMA上网的原理(其他泛泰机型可参考)7.13
  6. 锁屏界面
  7. android(NDK+JNI)---Eclipse+CDT+gdb调试android ndk程序
  8. 在Fragment中设置控件点击方法,执行失败。
  9. Android(安卓)version and Linux Kernel version

随机推荐

  1. Android(安卓)Duplicate files copied in
  2. 5 个顶级 Android(安卓)开源库
  3. 2010.12.16——— android listView 显示
  4. Android学习笔记SQLite
  5. 取消ScrollView滚动时的阴影
  6. Android(安卓)Push Notification Service
  7. 理解 Android(安卓)Build 系统
  8. Android(安卓)动画框架(一)转
  9. 如何安装 Android(安卓)SDK 和Eclipse 插
  10. Android(安卓)webkit 事件传递流程