zoukankan      html  css  js  c++  java
  • 寒假学习day13

    今天继续进行相对布局的学习。

    根据兄弟组件定位

    图中的组件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>
  • 相关阅读:
    docker 单kafka ,多分区
    spring data jpa + mysql使用json 类型
    C++ Multithread Tutorial
    GDB 调试程序
    C++ Project 积累(四)
    GDB 调试 C/C++ Project
    makefile 学习(一)
    Ubuntu 下配置 boost + eclipse
    C++ Project 积累(3)
    Leetcode Sudoku Solver
  • 原文地址:https://www.cnblogs.com/lxywsx/p/14905594.html
Copyright © 2011-2022 走看看