设为首页 加入收藏

TOP

Android开发实战(二十一):浅谈android:clipChildren属性(一)
2017-10-13 10:35:58 】 浏览:6922
Tags:Android 开发 实战 二十一 浅谈 android:clipChildren 属性

实现功能:

1、APP主界面底部模块栏

2、ViewPager一屏多个界面显示

3、........

 

首先需要了解一下这个属性的意思 ,即

是否允许子View超出父View的返回,有两个值true 、false  ,默认true

使用的时候给子View和根节点View控件都设置android:clipChildren="false",那么这个子View就不会限制在父View当中

-------------------------------------------------------------------------------------------------------------

下面通过两个项目中经常用到的例子来说明:

1、APP主界面底部模块栏

可以看出底部其实有一个ViewGroup(LinearLayout or RelativeLayout 灰色背景部分) 

但是我们要求中间一个图标按钮 是要比别的稍大点的,那么正常的我们写在一个LinearLayout中会出现下面这种情况

因为ViewGroup有高度限制,导致他也限制了它内部子View的高度,很显然达不到我们的需求。那么我们需要一种属性来让子View可以不受到父容器的限制

这就要用到了android:clipChildren属性

我们只需要给 根节点控件不想被父容器限制的子View 设置这个属性: android:clipChildren="false"  即可

布局代码:

<LinearLayout 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:background="#fff"
    android:clipChildren="false"
    tools:context="com.xqx.com.treat.ui.user.Login">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:orientation="horizontal"
        android:layout_gravity="bottom"
        android:background="#ddd"
        >

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#0000"
        android:scaleType="fitCenter"
        android:src="@mipmap/ic_launcher"
        />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#0000"
        android:scaleType="fitCenter"
        android:src="@mipmap/ic_launcher"
        />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="65dp"
        android:layout_weight="1"
        android:background="#0000"
        android:layout_gravity="bottom"
        android:scaleType="fitCenter"
        android:src="@mipmap/ic_launcher"
        />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#0000"
        android:scaleType="fitCenter"
        android:src="@mipmap/ic_launcher"
        />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#0000"
        android:scaleType="fitCenter"
        android:src="@mipmap/ic_launcher"
        />
        </LinearLayout>
</LinearLayout>
main

 

2、实现ViewPager一屏多个视图滚动

详细见各大APP应用市场 ,应用详情界面,会有类似图片滚动来显示应用功能的部分

首先实现该功能我们需要了解ViewPager,安卓开发_深入学习ViewPager控件

了解ViewPager的同学都知道,正常情况下我们一个手机界面只会显示出一个viewpager的子View视图

那么我们需要实现一个手机界面能看到多个子View视图该怎么办?

其实很简单,这里假设大家都会使用ViewPager并且已经写出了ViewPager的效果

第一步:

我们只需要在原来基础上在

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android添加图片到ListView或者 R.. 下一篇Android-正方形的容器

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目