记忆力随年龄减退了,干脆一些小知识点,也记录下来。
<RelativeLayout 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:padding="10dp"
tools:context=".MainActivity" >
<!-- android:padding此处定义整个布局和Activity四周距离,和网页的padding类同
-->
<!-- layout_marginTop 组件距离布局顶部距离 dp是单位 layout_toLeftOf组件左边缘
对齐靠近指定id的组件。
-->
<TextView
android:id="@+id/user"
android:layout_marginTop="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_toLeftOf="@+id/passtext"
android:text="用户:" />
<!-- layout_toRightOf组件右边缘靠近指定id的组件左边缘
layout_alignBottom 组件底部和指定id的组件底部对齐
-->
<EditText
android:id="@+id/usertext"
android:layout_toRightOf="@id/user"
android:layout_alignBottom="@id/user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="username"
/>
<!--
layout_alignBottom 组件底部和指定id的组件底部对齐
-->
<TextView
android:id="@+id/pass"
android:layout_alignBottom="@id/passtext"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"
/>
<!-- layout_toRightOf组件右边缘靠近指定id的组件左边缘
layout_below 组件处于指定id的组件下部
-->
<EditText
android:id="@+id/passtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/usertext"
android:layout_toRightOf="@id/pass"
android:text="password" />
<!-- layout_alignParentRight 组件和父布局右边靠近对齐
layout_below 位于指定id组件下部
-->
<Button
android:id="@+id/cancel"
android:text="cancel"
android:layout_alignParentRight="true"
android:layout_below="@id/passtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></Button>
<!-- layout_toLeftOf 组件左边缘和指定id组件右边缘靠近对齐
layout_below 位于指定id组件下部
-->
<Button
android:id="@+id/ok"
android:text="ok"
android:layout_toLeftOf="@id/cancel"
android:layout_below="@id/passtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></Button>
</RelativeLayout>布局效果图:
本文详细解析了一个具体的Android登录界面布局XML代码,介绍了各组件属性及其布局方式,并展示了布局的实际效果。
3221

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



