android技巧:神奇的android:clipChildren属性

来源:互联网 发布:linux 安装rpm包 编辑:程序博客网 时间:2024/04/30 14:12

前言:

今天在看微博的时候,发现了android:clipChildren属性的这么一个属性,感觉挺有意思的,对今后布局的搭建会很有帮助,特地研究了一下他的实现形式。

正文:

效果图:

之前大家实现上图中下部标题栏的思路是什么呢?大多数情况下,自己是在建立个RelativeLayout,今天看到android:clipChildren属性这个属性之后,才发现,之前的做法是多么的愚蠢!!

代码:

<?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" >

    <android.support.v4.view.ViewPager
        
android:id="@+id/view_pager"
        android:layout_width
="match_parent"
        android:layout_height
="0dip"
        android:layout_weight
="1.0" />

    <LinearLayout
        
android:layout_width="match_parent"
        android:layout_height
="48dip"
        android:background
="#B0C4DE"
        android:orientation
="horizontal" >

        <ImageView
            
android:layout_width="0dip"
            android:layout_height
="fill_parent"
            android:layout_weight
="1.0"
            android:scaleType
="fitCenter"
            android:src
="@mipmap/ic_launcher
" />

        <ImageView
            
android:layout_width="0dip"
            android:layout_height
="fill_parent"
            android:layout_weight
="1.0"
            android:scaleType
="fitCenter"
            android:src
="@mipmap/ic_launcher" />

        <ImageView
             
android:layout_width="0dip"
            android:layout_height
="64dip"
            android:layout_gravity
="bottom"
            android:layout_weight
="1.0"
            android:scaleType
="fitCenter"
            android:src
="@mipmap/ic_launcher" />

        <ImageView
            
android:layout_width="0dip"
            android:layout_height
="fill_parent"
            android:layout_weight
="1.0"
            android:scaleType
="fitCenter"
            android:src
="@mipmap/ic_launcher" />

        <ImageView
            
android:layout_width="0dip"
            android:layout_height
="fill_parent"
            android:layout_weight
="1.0"
            android:scaleType
="fitCenter"
            android:src
="@mipmap/ic_launcher" />
    </LinearLayout>

</LinearLayout>

当不在爷爷控件中设置android:clipChildren属性的时候,效果图为下图:

 

所以个人觉得,在实际的开发过程中,这个属性的用处还是大大滴!!

android:clipChildren的意思:是否限制子View在其范围内

原文博主还提到了这样一句话,在做动画的时候非常有用!!!好,就说到这里,希望大家多多交流,共同进步!

1 0