原理看完了,接下来按照上面的套路,我们以上面的布局和对齐方式,在LinearLayout121上添加三个上述布局的Button. 具体代码如下所示:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" android:text="aa"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="bb" android:layout_gravity="center" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="cc"/>
接下来就该运行了,下方是运行出来的结果:
(6)在线性布局中有一个不得不提的属性就是android:layout_weight, 该属性允许你以比例的形式来指定控件的大小。接下来我们要做的就是在LinearLayout122中添加三个水平方向上等分的按钮。使用android:layout_weight属性,很容易就可以实现,因为原理比较简单,就不画原理图了,下方是具体的xml实现:
<Button android:layout_width="pt" android:layout_height="wrap_content" android:layout_weight="" android:text="你好"/> <Button android:layout_width="pt" android:layout_height="wrap_content" android:layout_weight="" android:text="Android"/> <Button android:layout_width="pt" android:layout_height="wrap_content" android:layout_weight="" android:text="iOS"/>
具体运行效果如下所示:











