clipChildren

参考自:http://www.2cto.com/kf/201608/537822.html
实现功能:
1.底部导航栏的突出图标
2.viewpager一屏多个界面显示
android clipChildren与clipToPadding_第1张图片

android clipChildren与clipToPadding_第2张图片

如何实现:

1.底部导航栏的突出图标

注意:需放在根节点 android:clipChildren="false"

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_clip_children"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:clipChildren="false"    tools:context="com.sign.viewpagerdemo.ClipChildrenActivity">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="60dp"        android:layout_alignParentBottom="true"        android:background="#e7d321"        android:orientation="horizontal">        <ImageView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:scaleType="fitCenter"            android:src="@mipmap/ic_launcher" />        <ImageView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:scaleType="fitCenter"            android:src="@mipmap/ic_launcher" />        <ImageView            android:layout_width="wrap_content"            android:layout_height="90dp"            android:layout_gravity="bottom"            android:layout_weight="1"            android:scaleType="fitCenter"            android:src="@mipmap/ic_launcher" />        <ImageView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:scaleType="fitCenter"            android:src="@mipmap/ic_launcher" />        <ImageView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:scaleType="fitCenter"            android:src="@mipmap/ic_launcher" />    LinearLayout>RelativeLayout>

2.viewpager一屏多个界面显示

  1. 父布局需要 android:clipChildren="false"
  2. ViewPager宽度 android:layout_width="match_parent"
  3. 设置margin android:layout_marginLeft="80dp" android:layout_marginRight="80dp"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.sign.viewpagerdemo.MainActivity">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="200dp"        android:clipChildren="false"        android:gravity="center">        <android.support.v4.view.ViewPager            android:id="@+id/viewpager3"            android:layout_width="match_parent"            android:layout_height="200dp"            android:layout_marginLeft="80dp"            android:layout_marginRight="80dp"            android:clipChildren="false" />    LinearLayout>LinearLayout>

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

解决办法:将父类的touch事件分发至viewPager,linearLayout是ViewPager控件的父容器

linearLayout.setOnTouchListener(new View.OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                return viewPager.dispatchTouchEvent(event);            }        });

clipToPadding

当我们为ListView、ScrollView、GridView设置了paddingTop或paddingBottom的时候,我们发现当滑动到顶部和底部的时候,默认情况下padding/margin在滑动中一直存在,view总是不能滑动到最底部和最顶部,看起来很别扭。
如下图,左右两个recyclerview均设置了paddingtop,左边的未设置clipToPadding属性(默认为true),右边的设置clipToPadding为false
android clipChildren与clipToPadding_第3张图片

更多相关文章

  1. android 图片切换,仿百叶窗效果
  2. Android的图片压缩类ThumbnailUtils
  3. android 中给图片加圆角效果
  4. android图片轮播+点击跳转广告页面
  5. Android 下拉加载更多 上拉刷新 框架 (太极 八卦样式刷新,支持自定
  6. android button按键得到焦点和点击后改变背景图片
  7. Android 8.1隐藏状态栏图标

随机推荐

  1. 用Android(安卓)LiveCD体验Android(安卓)
  2. Android(安卓)线程学习
  3. 为Android加入busybox工具
  4. android:layout_gravity 和 android:grav
  5. Android单元测试之Testing和Instrumentat
  6. Android的Gradle插件
  7. 《Android深入透析》之Android事件分发机
  8. 如何在Android和iOS设备上录制游戏?
  9. 【转】有关Android线程的学习
  10. 如何在Android中使用OpenCV