实现功能:

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=""
android:background="#0000"
android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher"
/> <ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=""
android:background="#0000"
android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher"
/> <ImageView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight=""
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=""
android:background="#0000"
android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher"
/> <ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=""
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的效果

第一步:

我们只需要在原来基础上在布局文件里对ViewPager控件和它对应的根控件 添加 android:clipChildren="false"属性

第二步:

设置ViewPager的左右margin属性

android:layout_marginRight="80dp"

android:layout_marginLeft="80dp"

设置这两个属性的目的是什么呢?

首先,我们正常设置ViewPager控件的宽度都是

android:layout_width="match_parent"

而我们设置距离左右控件的距离之后,就会使ViewPager可现实的宽度变窄,如图,蓝色框部分就是viewpager可见部分

再加上第一步的设置

最终就出现这样的情况:一个界面我们可以看到至少2个起的viewpager中的子View(橙色,蓝色View视图)

注意点:该做法会有一个bug,就是只能滑动中间的那个View,而如果我们想要点着左边或者右边的View滑动怎么办?

解决办法:将父类的touch事件分发至viewPgaer,R.id.ly是ViewPager控件的父容器

findViewById(R.id.ly).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return viewpager.dispatchTouchEvent(event);
}
});

另外,activity代码中给ViewPager控件动态设置间距也会是效果大大提高

viewpager.setPageMargin();

ViewPager滚动效果:

ViewPager切换动画(3.0版本以上有效果)

效果图:

布局文件代码:

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="#fff"
android:id="@+id/ly"
android:clipChildren="false"
tools:context="com.xqx.com.treat.ViewPagerActivity"> <android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:clipChildren="false"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
></android.support.v4.view.ViewPager> </RelativeLayout>

Android开发实战(二十一):浅谈android:clipChildren属性的更多相关文章

  1. Android开发学习笔记:浅谈显示Intent和隐式Intent

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liangruijun.blog.51cto.com/3061169/655132 ...

  2. Android开发学习笔记:浅谈GridView

    GridView(网格视图)是按照行列的方式来显示内容的,一般用于显示图片,图片等内容,比如实现九宫格图,用GridView是首选,也是最简单的.主要用于设置Adapter. GridView常用的X ...

  3. Android开发(二十五)——Android上传文件至七牛

    设置头像: Drawable drawable = new BitmapDrawable(dBitmap); //Drawable drawable = Drawable.createFromPath ...

  4. Android开发学习笔记:浅谈WebView(转)

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liangruijun.blog.51cto.com/3061169/647456 ...

  5. Android开发学习笔记:浅谈WebView

    本文转自:http://www.2cto.com/kf/201108/101518.html WebView(网络视图)能加载显示网页,可以将其视为一个浏览器.它使用了WebKit渲染引擎加载显示网页 ...

  6. Android开发(二十一)——自动更新

    参考: [1] Android应用自动更新功能的代码实现.http://www.cnblogs.com/coolszy/archive/2012/04/27/2474279.html

  7. 转 Android开发学习笔记:浅谈WebView

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liangruijun.blog.51cto.com/3061169/647456 ...

  8. 浅谈Android应用保护(一):Android应用逆向的基本方法

    对于未进行保护的Android应用,有很多方法和思路对其进行逆向分析和攻击.使用一些基本的方法,就可以打破对应用安全非常重要的机密性和完整性,实现获取其内部代码.数据,修改其代码逻辑和机制等操作.这篇 ...

  9. 安卓开发_浅谈Android动画(四)

    Property动画 概念:属性动画,即通过改变对象属性的动画. 特点:属性动画真正改变了一个UI控件,包括其事件触发焦点的位置 一.重要的动画类及属性值: 1.  ValueAnimator 基本属 ...

  10. [转]浅谈Android五大布局(二)——RelativeLayout和TableLayout

    在浅谈Android五大布局(一)中已经描述了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoulteLayout(绝对布局)三种布局结构,剩下的两种布局Relati ...

随机推荐

  1. elasticsearch 集群

    elasticsearch 集群 搭建elasticsearch的集群 现在假设我们有3台es机器,想要把他们搭建成为一个集群 基本配置 每个节点都要进行这样的配置: cluster.name: ba ...

  2. ASP.NET MVC必知必会知识点总结(二)

    一.实现Controller的依赖注入: 1.自定义继承DefaultControllerFactory 类的控制器工厂类并重写GetControllerInstance方法:(如:InjectCon ...

  3. Vim魔法堂:认识快捷键绑定

    Brief 习惯在VS上按<F5>来编译运行程序,刚用上VIM上就觉得无比的麻烦,而随着对VIM的学习我们分阶段的简化这一操作 1. 退出VIM,在shell下编译&&运行 ...

  4. 两种CSS3圆环进度条详解

    晚上睡觉之前,我抽了1个多小时,研究了一下圆环进度条,结合从网上查阅的资料,我终于掌握了两种圆环的生成方法. 这次的效果就是单纯的CSS3效果,也没有写具体的JS,等以后有时间在好好整理一下吧~. 第 ...

  5. SQL Server 统计信息

    SELECT * FROM SYS.stats _WA_Sys_00000009_00000062:统计对象的名称.不同的机器名称不同,自动创建的统计信息都以_WA_Sys开头,00000009表示的 ...

  6. 介绍开源的.net通信框架NetworkComms框架 源码分析(五)ReservedPacketType

    原文网址: http://www.cnblogs.com/csdev Networkcomms 是一款C# 语言编写的TCP/UDP通信框架  作者是英国人  以前是收费的 目前作者已经开源  许可是 ...

  7. SSH服务器与Android通信(1)--服务器端发送数据

    很多应用要求SSH服务器不仅和PC通信,还要和Android移动设备通信,这时就需要用到JSON了.其基本原理是服务器将数据转换成JSON格式,发送给Android客户端,客户端再将JSON格式的数据 ...

  8. Dubbo入门

    早就听说了dubbo的好处,但是在项目中一直没有使用的机会,所以一直不知道怎么使用.今天晚上有空,简单的学习一下 就当入个门,以后项目中遇到的话,那么使用起来就比较简单了,至于介绍的话,我就不总结了, ...

  9. ahjesus使用T4模板自动维护实体

    在entity项目里新建模板DBEntity.tt <#@ template debug="false" hostspecific="true" lang ...

  10. Node.js的UnitTest单元测试

    body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; } 在专业化的软件开发过程中,无论什么平台语言,现在都需要UnitTes ...