控件布局(View)叠加效果

简介: 控件布局(View)叠加效果

 在开发android程序的时候,我们经常会遇到让控件或是view实现叠加的效果,如下图红圈部分所示:

20171122171639825.png


其他类似的效果图就不展示了,一般这种情况,我们用Framelayout来处理就可以了,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"      
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.baidu.mapapi.map.MapView
        android:id="@+id/bmapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true" />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="vertical"
        android:layout_marginLeft="30dp"
        android:layout_marginBottom="30dp"
        android:background="@color/white">
         <TextView
            android:id="@+id/baidu_student_positioning"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center"
            android:drawableTop="@mipmap/icon_positioning"
            android:layout_margin="5dp"
            android:text="@string/positioning"/>
        <TextView
            android:id="@+id/baidu_student_position"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center"
            android:drawableTop="@mipmap/icon_position"
            android:layout_margin="5dp"
            android:text="@string/position"/>
        <TextView
            android:id="@+id/baidu_student_track"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center"
            android:drawableTop="@mipmap/icon_track"
            android:layout_margin="5dp"
            android:text="@string/track"/>
        <TextView
            android:id="@+id/baidu_student_setting"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_gravity="center"
            android:drawableTop="@mipmap/icon_setting"
            android:layout_margin="5dp"
            android:text="@string/setting"/>
    </LinearLayout>
</FrameLayout>


这样效果就出来了,但是这又带来了一个问题,Framelayout在布局上会有很多限制,不如RelativeLayout布局那么随意,那么RelativeLayout有没有什么属性可以让我们来处理叠加的效果呢,答案是肯定的。


 在控制的属性中会有四个属性 :


 android:layout_marginTop

 android:layout_marginBottom

 android:layout_marginLeft

 android:layout_marginRight.


 通过设置上面四个属性为负值来实现相邻view之间的叠加效果,如android:layout_marginLeft=”-50dp”,这样就可以实现控制叠加的效果了,不过谁叠加谁,就要看控制在xml中的位置了,简单试一下,就会出现你想要的结果了。


这里给出 RelativeLayout布局的属性:

// 相对于给定ID控件  
android:layout_above 将该控件的底部置于给定ID的控件之上;  
android:layout_below 将该控件的底部置于给定ID的控件之下;  
android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;  
android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;  
android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;  
android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;  
android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;  
android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;  
android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;  
// 相对于父组件  
android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;  
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;  
android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;  
android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;  
// 居中  
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;  
android:layout_centerVertical 如果为true,将该控件的置于垂直居中;  
android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;  
// 指定移动像素  
android:layout_marginTop 上偏移的值;  
android:layout_marginBottom 下偏移的值;  
android:layout_marginLeft   左偏移的值;  
android:layout_marginRight   右偏移的值;  




相关文章
|
4月前
|
安全 网络协议 数据建模
网站 HTTPS 证书怎么选?阿里云DV 域名验证、OV 组织验证、EV 扩展验证指南及选择方法
阿里云SSL证书分DV(域名验证)、OV(组织验证)、EV(扩展验证)三类:DV适合个人/测试,15分钟签发;OV适合企业官网,需人工审核,显示企业信息;EV为最高级别,适用于金融、政务等高安全场景。阿里云SSL证书官网:https://t.aliyun.com/U/RpER2D
204 0
|
安全 Shell 网络安全
解决Git错误“WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!”的方法
注意,维护安全和遵循最佳实践是处理此类问题的关键。如果对服务器或网络安全性有疑问,请寻求专业的网络管理员或安全专家的帮助。在企业环境中频繁遇到此类问题时应重新评估安全协议和服务器管理流程。
915 10
|
安全 算法 网络安全
一文读懂 RSA 加密:非对称加密的基石
RSA是应用最广泛的非对称加密算法,由Rivest、Shamir和Adleman于1977年提出。它基于大数分解难题,使用公钥加密、私钥解密,解决密钥分发问题,广泛用于HTTPS、数字签名等安全通信场景,是现代网络安全的基石之一。
5650 0
|
存储 Ubuntu Linux
关于实体机安装Ubuntu 22.04.3-desktop-amd64遇见的一些问题
【10月更文挑战第5天】本文介绍了Ubuntu安装过程中常见的四个问题及其解决方案,包括分区设置、驱动问题、软件安装问题和启动问题。对于分区,推荐新手选择自动分区,手动分区需了解基本概念。驱动问题可通过安装相应硬件的Linux驱动解决。软件安装问题可更换国内镜像源或修复依赖关系。启动问题则可尝试进入恢复模式修复或根据错误提示信息寻求帮助。
1361 3
|
Android开发
Android PackageManagerService源码分析和APK安装原理详解
Android PackageManagerService源码分析和APK安装原理详解
1710 1
|
存储 安全 NoSQL
pthread_getspecific和pthread_setspecific详解
pthread_getspecific和pthread_setspecific详解
|
Linux Go iOS开发
Go语言新手指南:正确使用GOPATH的步骤
Go语言新手指南:正确使用GOPATH的步骤
7194 0
用户态和内核态是如何切换的?
【10月更文挑战第28天】用户态和内核态的切换是通过系统调用指令、异常和中断等机制来实现的。这些机制确保了应用程序能够在需要时请求内核提供的服务,同时也保证了内核能够对系统资源进行有效的管理和保护,维护系统的稳定性和安全性。通过准确地保存和恢复上下文信息,实现了用户态和内核态之间的无缝切换,为计算机系统的正常运行提供了有力保障。
|
Android开发
Android--fragment与activity及两个fragment之间的跳转实现
在应用的交互中,我可能需要实现: 从当前的fragment跳转到另一个fragment 从当前的fragment跳转到一个activity中 从当前的activity跳转到一个fragment中 网上提供的思路较多,这里总结了一套自己的方法。
2683 0
|
小程序 前端开发 持续交付
小程序全栈开发中的CI/CD流程与自动化部署是一种高效的开发模式。
本文探讨小程序全栈开发中的CI/CD流程与自动化部署,介绍持续集成与部署的概念,包括自动化构建、测试、代码审查及部署实践。通过提高代码质量、迭代速度及团队协作效率,确保小程序稳定运行与良好用户体验。
704 2