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>
  • 相关阅读:
    C++中随机函数
    在cocos2d里面如何使用Texture Packer和像素格式来优化spritesheet
    CCParticleSystem粒子系统
    Redis百亿级Key存储方案
    Mongodb亿级数据量的性能测试
    mysql-mongdb-redis
    java常用的几种线程池比较
    Java中的多线程
    MySQL技术内幕InnoDB存储引擎(表&索引算法和锁)
    B+树介绍
  • 原文地址:https://www.cnblogs.com/wrx166/p/14909437.html
Copyright © 2011-2022 走看看