Android开发总结笔记 LinearLayout(线性布局) 1-1-1
2015-09-21 16:05
501 查看
LinearLayout的继承结构
事实上所有的布局类都会继承ViewGroup这个类。从字面上理解,ViewGroup就是一组View的意思。(LinearlayoutAPI)
下面来看一下LinearLayout在xml中的一些属性吧
android:orientation两个值:Vertical垂直Horizontal水平
android:divider参数必须是一个shape或者一张图片、结合showDividers和dividerPadding属性使用,要设置宽高才能显示出来,如果android:shape使用line,只能用stroke来显示颜色
子控件中的android:weight属性表示该组件在linearLayout中所占的权重。
shape.xml
activity_main.xml
效果图:
android:baseLineAligned基准线的概念:
红色那条就是基准线
设置前
设置后
android:baseLineAlignedChildIndex这个属性也是一样的原理
android:measureWithLargestChild少用。直接忽略了。
重要提示
当android:orientation="vertical"时,只有水平方向的设置才起作用,垂直方向的设置不起作用。
即:left,right,center_horizontal是生效的。
当android:orientation="horizontal"时,只有垂直方向的设置才起作用,水平方向的设置不起作用。
即:top,bottom,center_vertical是生效的
事实上所有的布局类都会继承ViewGroup这个类。从字面上理解,ViewGroup就是一组View的意思。(
下面来看一下LinearLayout在xml中的一些属性吧
XML属性 | 对应JAVA方法 |
android:orientation | setOrientation(int) |
android:weightNum | |
android:divider | setDividerDrawable(Drawable) |
android:gravity | setGravity(int) |
android:baseLineAligned | setBaseLineAligned(boolean) |
android:baseLineAlignedChildIndex | setBaseLineAlignedChildInxex(int) |
android:measureWithLargestChild | setMeasureWithLargestChildEnable(boolean) |
android:divider参数必须是一个shape或者一张图片、结合showDividers和dividerPadding属性使用,要设置宽高才能显示出来,如果android:shape使用line,只能用stroke来显示颜色
子控件中的android:weight属性表示该组件在linearLayout中所占的权重。
shape.xml
<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="5dp"
android:height="5dp"></size>
<solidandroid:color="@android:color/black"></solid>
</shape>
activity_main.xml
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="true"
android:divider="@drawable/shape"
android:orientation="vertical"
android:showDividers="middle">
<TextView
android:layout_width="100dp"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_blue_bright"
android:text="android"
android:textSize="20sp"/>
<TextView
android:layout_width="100dp"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_green_dark"
android:gravity="center_vertical"
android:text="Iloveit"
android:textSize="20sp"/>
</LinearLayout>
效果图:
android:baseLineAligned基准线的概念:
红色那条就是基准线
设置前
设置后
android:baseLineAlignedChildIndex这个属性也是一样的原理
android:measureWithLargestChild少用。直接忽略了。
重要提示
当android:orientation="vertical"时,只有水平方向的设置才起作用,垂直方向的设置不起作用。
即:left,right,center_horizontal是生效的。
当android:orientation="horizontal"时,只有垂直方向的设置才起作用,水平方向的设置不起作用。
即:top,bottom,center_vertical是生效的
相关文章推荐
- android 百分比布局(percentLayout),妈妈再也不用担心适配问题了
- android 事件总线 -- Otto(一)
- android开发步步为营之77:android数据库ORM之greenDAO
- Android-在线查看源码
- Android开源组件SlidingMenu的基本使用方法和SlidingMenuDemo
- Android中常见的像素单位
- android获取系统wifi状态等
- Android Studio快捷键设置
- 【android】通过leakCanary找出程序内存泄露点
- Android布局优化之<merge>与<ViewStub>标签使用
- Android自定义View示例(一)—带有删除按钮的EditText
- Android快速开发工具GsonFormat使用教程
- android弹出下拉选择菜单,单选,多选【运行截图——图】
- android Bitmap getByteCount和getRowBytes
- android studio集成svn
- 解决android代码中重复写findViewByid()
- android客户端性能测试 (一)
- Android 性能测试
- Android 官方推荐 : DialogFragment 创建对话框
- android布局相关