Android clipChildren屬性實例詳解
前言
前幾天有在微博上推薦過一個博客,看他文章時發(fā)現了這個屬性。有些屬性不常用,但需要的時候非常有用,于是做了個例子,正好項目用到,與大家分享一下。
正文
一、效果圖

看到這個圖時你可以先想想如果是你,你怎么實現這個效果。馬上想到用RelativeLayout?NO,NO,NO,,,
二、實現代碼
<?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="@drawable/ic_launcher" />
<ImageView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:scaleType="fitCenter"
android:src="@drawable/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="@drawable/ic_launcher" />
<ImageView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
<ImageView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
代碼說明:
1、只需在根節(jié)點設置android:clipChildren為false即可,默認為true。
2、可以通過android:layout_gravity控制超出的部分如何顯示。
3、android:clipChildren的意思:是否限制子View在其范圍內。
結束:
以上例子在做Android 動畫的時候非常有用,有需要的朋友可以參考下。
相關文章
Android 給圖片加上水印的示例代碼(支持logo+文字)
本篇文章主要介紹了Android 給圖片加上水印的示例代碼(支持logo+文字),具有一定的參考價值,有興趣的可以了解一下2017-08-08
Android studio開發(fā)小型對話機器人app(實例代碼)
這篇文章主要介紹了Android studio開發(fā)一個小型對話機器人app,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
AndroidStudio接入Unity工程并實現相互跳轉的示例代碼
這篇文章主要介紹了AndroidStudio接入Unity工程并實現相互跳轉,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12
Android自定義View之組合控件實現類似電商app頂部欄
這篇文章主要為大家詳細介紹了Android自定義View之組合控件,實現類似電商app頂部欄的相關資料,具有參考價值,感興趣的小伙伴們可以參考一下2016-05-05

