zoukankan      html  css  js  c++  java
  • Android-相对布局(RelativeLayout)

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

       相对布局这里面到所有控件,都是有相对性的
                           1.相对与父控件 
                           2.相对与和自己平级的控件

    </RelativeLayout>


    虽然相对布局需要对没有控件设置ID,才能使用,看起来LinearLayout方便写,实际上RelativeLayout更加对灵活,因为线性布局设置垂直或者水平就整版都是垂直与水平的,相对布局控制更加灵活写


    相对布局,如果不指定ID,默认都是在左上角



    相对bt_444控件中间线对齐:
    android:layout_alignBaseline="@id/bt_333"

    相对bt_444控件顶部对齐:

    android:layout_alignTop="@id/bt_333"

    相对bt_444控件的底部对齐:

    android:layout_alignBottom="@id/bt_333"

    <!--
        相对于父控件系列:
    
                相对于父控件垂直居中
                android:layout_centerVertical="true"
    
                相对于父控件水平居中
                android:layout_centerHorizontal="true"
    
                相对于父控件正中间
                android:layout_centerInParent="true"
    
                相对于父控件的右边
                android:layout_alignParentRight="true"
    
                相对于父控件的左边
                android:layout_alignParentLeft="true"
    
                相对于父控件的顶部
                android:layout_alignParentTop="true"
    
                相对于父控件的底部
                android:layout_alignParentBottom="true"
    
                相对于父控件的结束(通常情况下是在父控件最右边)
                android:layout_alignParentEnd="true"
    
                相对于父控件的开始 最左边 相对布局的默认
                android:layout_alignParentStart="true"
    
            相对于平级控件系列:
    
                相对于bt_111控件的底部
                android:layout_below="@+id/bt_111"
    
                相对于bt_111控件的顶部
                android:layout_above="@id/bt_111"
    
                相对于bt_111控件的右边
                android:layout_toRightOf="@id/bt_111"
    
                相对于bt_111控件的左边
                android:layout_toRightOf="@id/bt_111"
    
                相对与控件的中间对齐
                android:layout_alignBaseline="@id/bt_333"
    
                相对与控件的顶部对齐
                android:layout_alignTop="@id/bt_333"
    
                相对与控件的底部对齐
                android:layout_alignBottom="@id/bt_333"
    
                相对与控件的中间对齐
                android:layout_alignBaseline="@id/bt_333"
    
                相对与控件的左对齐
                android:layout_alignLife="@id/bt_333"
    
                相对与控件的右对齐
                android:layout_alignRight="@id/bt_333"
    
    
                // 外边距 上下左右 一般情况下用于 View
                android:layout_marginTop="20dp"
                android:layout_marginLeft="20dp"
                android:layout_marginBottom="20dp"
                android:layout_marginRight="20dp"
                android:layout_margin="20dp"
    
                外边距往水平方向80dp
                android:layout_marginHorizontal="80dp"
    
                外边距往垂直方向80dp
                android:layout_marginVertical="80dp"
    
    
                // 内边距 上下左右 一般情况下用于 ViewGroup 用来管控View
                android:padding="40dp"
                android:paddingLeft="40dp"
                android:paddingRight="40dp"
                android:paddingTop="40dp"
                android:paddingBottom="40dp"
    
                内边距往水平方向60dp
                android:paddingHorizontal="60dp"
    
                内边距往垂直方向60dp
                android:paddingVertical="60dp"
    -->

    相对布局测试的代码:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <Button
            android:id="@+id/bt_111"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1111"
    
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:layout_centerInParent="true"
    
            />
    
        <Button
            android:id="@+id/bt_222"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2222"
            android:layout_toLeftOf="@id/bt_111"
            android:layout_centerInParent="true"
            />
    
        <Button
            android:id="@+id/bt_333"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:text="333"
            android:layout_marginLeft="130dp"
            android:layout_marginTop="130dp"
            android:background="#f00"
            />
    
        <Button
            android:id="@+id/bt_444"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:text="444"
            android:layout_toRightOf="@id/bt_333"
            android:layout_alignBaseline="@id/bt_333"
            android:background="@color/colorAccent"
             />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="555"
            android:layout_alignParentStart="true"
            />
    
    </RelativeLayout>
  • 相关阅读:
    target runtime apache v6.0 not defined解决
    java.lang.AbstractMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servlet/ServletContext;)Ljavax/servlet/jsp/JspApplicationContext;
    The valid characters are defined in RFC 7230 and RFC 3986问题
    invalid END header解决方法
    You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed问题解决
    Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
    在eclipse中import java web项目时遇到的一些问题并将该项目通过tomcat发布
    java byte转string 涉及到字节流中有中文
    spring+mybatis框架搭建时遇到Mapped Statements collection does not contain value for...的错误
    试试看读一下Zepto源码
  • 原文地址:https://www.cnblogs.com/android-deli/p/10092872.html
Copyright © 2011-2022 走看看