Android 布局2.线性布局与框架布局

1.线性布局

①android:layout_weight权重的描述:

layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。  所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视  图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight 。

②android:layout_gravity设置对齐方式

以上两种属性是线性布局中最重要的属性,使用线性布局可是设置出所有的图形格式,但是布局嵌套布局不建议使用。


2.框架布局

框架布局是最简单的布局方式、所有添加到这个布局中的视图都是以层叠的方式显示。第一个添加到框架布局中的视图显示在最底层,最后一个被放在最顶层,上一层的视图会覆盖下一层的视图,因此框架布局类似堆栈布局



当要做图片的重叠显示的时候可以选择框架布局。

3.相对布局

RelativeLayout可以设置某一个视图相对于其他视图的位置,这些位置可以包括上下左右等。



以上的属性可以相互配合使用实现左上,右上,左下,右下的显示视图。实现代码如下:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:gravity="center" android:layout_width="fill_parent"
	android:layout_height="fill_parent">

	<Button android:id="@+id/button1" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:text="Button2"
		android:textSize="16dp"></Button>

	<Button android:layout_width="wrap_content" android:id="@+id/button2"
		android:layout_height="wrap_content" android:text="Button"
		android:textSize="16dp" android:layout_toRightOf="@id/button1"
		android:layout_below="@id/button1"></Button>

	<Button android:id="@+id/button3" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:text="Button2"
		android:textSize="16dp" android:layout_toLeftOf="@id/button2"
		android:layout_below="@id/button2"></Button>

	<Button android:id="@+id/button4" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:text="Button3"
		android:textSize="16dp" android:layout_toRightOf="@id/button2"
		android:layout_above="@id/button2"></Button>
		
	<Button android:id="@+id/button5" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:text="Button4"
		android:textSize="16dp" android:layout_toRightOf="@id/button2"
		android:layout_below="@id/button2"></Button>
</RelativeLayout>


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值