RelativeLayout相对布局各种常见的问题

发布时间:2020-08-06 19:19:46 作者:吃素只吃肉
来源:网络 阅读:1872

  我是一个新手,刚开始接触android,我就今天学到的Relativelayout来和大家分享一下。

 


  

相对布局基本概念:一个控件的位置它决定于它和其他控件的关系,

好处:比较灵活;缺点:掌握比较复杂。

鉴于以上几点,所以要多进行练习,才能熟练掌握Relativelayout




Relativelayout常用属性;

子类控件相对子类控件:值是另外一个控件的id

android:layout_above----------位于给定DI控件之上

android:layout_below ----------位于给定DI控件之下

android:layout_toLeftOf -------位于给定控件左边

android:layout_toRightOf ------位于给定控件右边

android:layout_alignLeft -------左边与给定ID控件的左边对齐

android:layout_alignRight ------右边与给定ID控件的右边对齐

android:layout_alignTop -------上边与给定ID控件的上边对齐

android:layout_alignBottom ----底边与给定ID控件的底边对齐

android:layout_alignBaseline----对齐到控件基准线

相对父容器,值是true或false

android:layout_alignParentLeft ------相对于父靠左

android:layout_alignParentTop-------相对于父靠上

android:layout_alignParentRight------相对于父靠右

android:layout_alignParentBottom ---相对于父靠下

android:layout_centerInParent="true" -------相对于父即垂直又水平居中

android:layout_centerHorizontal="true" -----相对于父即水平居中

android:layout_centerVertical="true" --------相对于父即处置居中相对于父容器位置:

android:layout_margin="10dp"

android:layout_marginLeft

android:layout_marginRight

android:layout_marginTop

android:layout_marginBottom





相对布局的例子


<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent">

    <TextView

        android:layout_width="100dp"

        android:layout_height="100dp"

        android:id="@+id/view1"

        android:background="@drawable/user"

        android:layout_centerInParent="true"

        />

    <TextView

        android:layout_width="100dp"

        android:layout_height="100dp"

        android:id="@+id/view2"

        android:background="@drawable/user"

        android:layout_above="@+id/view1"

        android:layout_alignLeft="@+id/view1"

        />

    <TextView

        android:layout_width="100dp"

        android:layout_height="100dp"

        android:id="@+id/view3"

        android:background="@drawable/user"

        android:layout_below="@+id/view1"

        android:layout_alignLeft="@+id/view1"

        />

    <TextView

        android:layout_width="100dp"

        android:layout_height="100dp"

        android:id="@+id/View4"

        android:background="@drawable/user"

        android:layout_toLeftOf="@+id/view1"

        android:layout_alignTop="@+id/view1"

        />

    <TextView

        android:layout_width="100dp"

        android:layout_height="100dp"

        android:id="@+id/view5"

        android:background="@drawable/user"

        android:layout_toRightOf="@+id/view1"

        android:layout_alignTop="@+id/view1">

RelativeLayout相对布局各种常见的问题

        </TextView>





</RelativeLayout>





推荐阅读:
  1. android的相对布局
  2. android 设置LinearLayout,RelativeLayout等等layout的高和宽

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

studio android relativelayout

上一篇:便携的J2EE应用 (转)

下一篇:less嵌套

相关阅读

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

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