前言
这两天在开发过程中,用到了许多动画,其中就有缩放动画,图片在放大之后,超出了原本的区域范围,然后就导致图片的一部分被截掉了,感觉略显尴尬哈,这怎么能行呢,于是乎,一顿学习(百度)之下,发现了clipChildren属性,很强大的样子,一顿操作后,完美解决~~
用法
- clipChildren属性需要设置在最外层的根布局中。
- clipChildren是布尔值类型,true表示动画被限定在父布局的区域之内,false表示动画可以超过父布局的边界。
代码中的应用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:clipChildren="false"
>
<FrameLayout
android:layout_width="24dp"
android:layout_height="24dp">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@mipmap/ic_launcher"
android:scaleType="centerCrop"
/>
</FrameLayout>
<FrameLayout
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@color/colorPrimary"
/>
</RelativeLayout>
效果图
紫色区域是我们父布局的限定区域,但是在使用了clipChildren属性之后,我们的ImageView的大小就扩展到48dp了,是不是很神奇呀,快来试一试吧~~