Android设置android:clipChildren达到的特殊UI设计效果



Android设置android:clipChildren达到的特殊UI设计效果

在Android的布局XML文件中,有一个不常用的属性android:clipChildren,该属性值可设为true或者false。
该属性控制Android的一个子view是否运行超越父控件边界放置。Android系统默认赋予该属性值是true,即不允许超越所在父布局的边界。如果设置为false,则表示允许该子view超越父布局的边界。
当把android:clipChildren的属性设置为false后,在Android的UI设计中会产生一些比较有趣的设计效果,比如下面一个在LinearLayout布局中简单水平并排放置的若干ImageView效果,如图:


其实现代码(布局XML)为:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dip"
        android:background="#e57373" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dip"
        android:background="#2196f3"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:layout_gravity="bottom"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="70dip"
            android:layout_gravity="bottom"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="90dip"
            android:layout_gravity="bottom"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="110dip"
            android:layout_gravity="bottom"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="130dip"
            android:layout_gravity="bottom"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="150dip"
            android:layout_gravity="bottom"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="170dip"
            android:layout_gravity="bottom"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dip"
        android:background="#4dd0e1" />
</LinearLayout>


android:layout_gravity="bottom" , 告知Android系统要从底部向上绘制该子view。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangphil

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值