添加一个< AbsoluteLayout>绝对布局管理器,然后分别添加一个TextView组件和一个Button组件,并分别通过android:layout_x和android:layout_y属性设置它们的绝对位置。
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.shenfan.absolutelayout.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="20px"
android:layout_y="10px"
android:text="用户名"
/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_x="50px"
android:layout_y="100px"
android:text="确定"/>
</AbsoluteLayout>
本文详细介绍了如何使用Android中的AbsoluteLayout绝对布局管理器,通过具体的XML代码示例展示了如何设置TextView和Button组件的精确位置,深入理解绝对布局的使用场景和限制。
3万+

被折叠的 条评论
为什么被折叠?



