absolutelayout 屏幕外 android,android基础之AbsoluteLayout布局

本文介绍了Android开发中Absolute布局的工作原理,通过示例展示了如何使用layout_x和layout_y属性精确设置组件位置。然而,由于在不同设备和分辨率上可能无法良好适配,文章建议避免在实际开发中过度依赖Absolute布局。
摘要由CSDN通过智能技术生成

Absolute布局:

组件的位置可以准确的指定在屏幕的x/y坐标位置

虽然可以精确的去规定坐标,但是不建议使用。因为不同的设备  不同的分辨率的手机移动设备上不能很好的显示应有的效果

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

>

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:text="Button1"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="button2"

/>

运行结果如下:

ee3d85e6ad256e8e9024fee0167ba315.png

layout_x和layout_y属性:可以设置具体的x/y坐标

代码如下:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

>

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:text="Button1"

android:layout_x="100dp"

/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="button2"

android:layout_y="100dp"

/>

运行如下:

e9ea099f98433fcda3c17ee8b44bc0da.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值