温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

android基础之RelativeLayout布局

发布时间:2020-06-19 19:44:05 来源:网络 阅读:479 作者:hagar 栏目:移动开发

RelativeLayout布局 

在相对布局中,至少要确定组件的“左右“ “上下” 两个位置才能准确固定组件位置

组件之间的位置关系:

android:layout_above 

android:layout_above="@id/btn2"表示与id为btn2的组件的上边缘对齐

android:layout_below

android:layout_toLeftOf

android:layout_toRightOf

组件对齐方式:

android:layout_alignBaseline 将该组件放在指定id组件进行中心线对齐

android:layout_alignTop

android:layout_alignBottom

android:layout_alignLeft

android:layout_alignRight

当前组件与父组件的对齐方式:

android:layout_alignParentTop与父组件进行顶部对齐

android:layout_alignParentBottom

android:layout_alignParentLeft

android:layout_alignParentRight

组件放置位置:

android:layout_centerHorizontal放置在水平方向的中央位置

android:layout_centerVertical放置为垂直方向的中央位置

android:layout_centerInParent放置在父组件的水平中央及垂直中央的位置


以下代码示例:

<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:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="Button1"

    android:id="@+id/btn1"

    />

    <Button

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="Button2"

        android:id="@+id/btn2"

        android:layout_below="@id/btn1"

        />

    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Button3"

        android:id="@+id/btn3"

        android:layout_below="@id/btn2"

        android:layout_alignParentRight="true"

        />

     <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="Button4"

         android:id="@+id/btn4"

         android:layout_below="@id/btn3"

         android:layout_alignParentRight="true"

         />

     <Button

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="Button5"

         android:id="@+id/btn5"

         android:layout_below="@id/btn4"

         android:layout_centerHorizontal="true"

         />

</RelativeLayout>

android基础之RelativeLayout布局


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI