布局定位函数:
根据父容器:
-
左对齐:android:layout_alighParentLeft
-
右对齐:android:layout_alighParentRight
-
顶端对齐:android:layout_alighParentTop
-
底部对齐:android:layout_alighParentBottom
-
水平居中:android:layout_centerHorizontal
-
垂直居中:android:layout_centerVertical
-
中央位置:android:layout_centerInParent
根据其他组件:(后加组件id值)
-
左边:android:layout_toLeftOf
-
右边:android:layout_toRightOf
-
上方:android:layout_above
-
下方:android:layout_below
-
对齐上边界:android:layout_alignTop
-
对齐下边界:android:layout_alignBottom
-
对齐左边界:android:layout_alignLeft
-
对齐右边界:android:layout_alignRight
示例
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="150dp"
android:textSize="100dp"
android:textColor="#3CB371"
android:gravity="right"
android:text="0"
android:id="@+id/tv1"
/>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:text="C"
android:textSize="35dp"
android:textColor="#ff0000"
android:layout_below="@id/tv1"
android:id="@+id/btn_c"
/>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:text="Back"
android:textSize="20dp"

最低0.47元/天 解锁文章
1748

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



