zoukankan      html  css  js  c++  java
  • clipChildren属性

    clipChildren属性表示是否限制子控件在该容器所在的范围内,clipChildren属性配合layout_gravity属性,可以用来设置多余部分的显示位置,我这里举一个简单的例子,比如喜马拉雅FM这个应用的首页:

    大家注意看这个应用底部导航栏中中间一个是要比另外四个高的,这种效果很多人就会想到使用一个RelativeLayout布局来实现,其实不用那么麻烦,这种效果一个clipChildren属性就能实现,示例Demo如下:

    代码:

    <?xml version="1.0" encoding="utf-8"?>  
    <RelativeLayout  
        xmlns:android="http://schemas.android.com/apk/res/android"  
        xmlns:tools="http://schemas.android.com/tools"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:clipChildren="false"  
        tools:context="org.lenve.clipchildren.MainActivity">  
      
        <LinearLayout  
            android:layout_width="match_parent"  
            android:layout_height="48dp"  
            android:layout_alignParentBottom="true"  
            android:background="#03b9fc"  
            android:orientation="horizontal">  
      
            <ImageView  
                android:layout_width="0dp"  
                android:layout_height="match_parent"  
                android:layout_weight="1"  
                android:src="@mipmap/ic_launcher"/>  
      
            <ImageView  
                android:layout_width="0dp"  
                android:layout_height="match_parent"  
                android:layout_weight="1"  
                android:src="@mipmap/ic_launcher"/>  
      
            <ImageView  
                android:layout_width="0dp"  
                android:layout_height="72dp"  
                android:layout_gravity="bottom"  
                android:layout_weight="1"  
                android:src="@mipmap/ic_launcher"/>  
      
            <ImageView  
                android:layout_width="0dp"  
                android:layout_height="match_parent"  
                android:layout_weight="1"  
                android:src="@mipmap/ic_launcher"/>  
      
            <ImageView  
                android:layout_width="0dp"  
                android:layout_height="match_parent"  
                android:layout_weight="1"  
                android:src="@mipmap/ic_launcher"/>  
        </LinearLayout>  
    </RelativeLayout> 
    

    大家看只需要在根节点添加clipChildren属性,然后在第三个ImageView上添加layout_gravity属性即可,layout_gravity属性值为bottom表示控件大小超出后控件底部对齐。效果如下:

  • 相关阅读:
    2020-06-20 助教一周小结(第十七周)
    2020-06-14 助教一周小结(第十六周)
    2020-06-7助教一周小结(第14周)
    2020本科校招-从小白到拿到30k offer的学习经历
    2020-05-24助教一周小结(第13周)
    2020-05-17 助教一周小结(第十二周)
    2020-05-10 助教一周小结(第十一周)
    2020-05-04 助教一周小结(第十周)
    2020-04-26 助教一周小结(第九周)
    Ngnix搭建静态网页和安装wordpress
  • 原文地址:https://www.cnblogs.com/foxy/p/7849830.html
Copyright © 2011-2022 走看看