zoukankan      html  css  js  c++  java
  • Android随笔

    a相对布局

    核心属性图


    2.父容器定位属性示意图


    3.根据兄弟组件定位

    恩,先说下什么是兄弟组件吧,所谓的兄弟组件就是处于同一层次容器的组件,如图

    图中的组件1,2就是兄弟组件了,而组件3与组件1或组件2并不是兄弟组件,所以组件3不能通过 组件1或2来进行定位,比如layout_toleftof = "组件1"这样是会报错的!切记! 关于这个兄弟组件定位的最经典例子就是"梅花布局"了,下面代码实现下:

    运行效果图:

    实现代码:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
        xmlns:tools="http://schemas.android.com/tools"    
        android:id="@+id/RelativeLayout1"    
        android:layout_width="match_parent"    
        android:layout_height="match_parent" >    
        
        <!-- 这个是在容器中央的 -->    
            
        <ImageView    
            android:id="@+id/img1"     
            android:layout_width="80dp"    
            android:layout_height="80dp"    
            android:layout_centerInParent="true"    
            android:src="@drawable/pic1"/>    
            
        <!-- 在中间图片的左边 -->    
        <ImageView    
            android:id="@+id/img2"     
            android:layout_width="80dp"    
            android:layout_height="80dp"    
            android:layout_toLeftOf="@id/img1"    
            android:layout_centerVertical="true"    
            android:src="@drawable/pic2"/>    
            
        <!-- 在中间图片的右边 -->    
        <ImageView    
            android:id="@+id/img3"     
            android:layout_width="80dp"    
            android:layout_height="80dp"    
            android:layout_toRightOf="@id/img1"    
            android:layout_centerVertical="true"    
            android:src="@drawable/pic3"/>    
            
        <!-- 在中间图片的上面-->    
        <ImageView    
            android:id="@+id/img4"     
            android:layout_width="80dp"    
            android:layout_height="80dp"    
            android:layout_above="@id/img1"    
            android:layout_centerHorizontal="true"    
            android:src="@drawable/pic4"/>    
            
        <!-- 在中间图片的下面 -->    
        <ImageView    
            android:id="@+id/img5"     
            android:layout_width="80dp"    
            android:layout_height="80dp"    
            android:layout_below="@id/img1"    
            android:layout_centerHorizontal="true"    
            android:src="@drawable/pic5"/>    
        
    </RelativeLayout>
  • 相关阅读:
    【计算机世界】467- XOR — 神奇的按位运算符
    记 · 复习知识 · 偶遇好玩的知识点
    【CSS】466- 一行 CSS 代码搞定响应式布局
    【Web技术】465- 关于前端埋点统计方案思考
    【CSS】464- 5种 CSS 浮动和清除浮动的方法
    简单易懂的 React useState() Hook 指南(长文建议收藏)
    java中的四类八种
    线程
    异常
    Aspx Ajax 调用 C#函数处理数据
  • 原文地址:https://www.cnblogs.com/wrx166/p/14909437.html
Copyright © 2011-2022 走看看