设计一个界面,整个界面包含一个listview,但是listview不是全部充满屏幕,如下:

可能会这样设计布局

<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="#2262" android:orientation="vertical" >    <ListView  android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:paddingTop="16dp" >    </ListView></LinearLayout>

但是这里有个问题:滚动时顶部不能填充

这时候就需要
android:clipToPaddingandroid:clipChildren
官方文档:

clipToPadding:控件的绘制区域是否在padding里面, 值为true时padding那么绘制的区域就不包括padding区域;
定义一个孩子是否仅限于画里面的界限。
clipChildren:当ViewGroup的Padding不为0时,定义ViewGroup是否裁剪子孩子的填充。

这两个属性默认是true的,所以在设置了padding情况下,默认滚动是在 padding内部的,要达到上面的效果主要把这两个属性设置了false那么这样子控件就能画到padding的区域了。

修改后的代码

<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="#2262" android:orientation="vertical" >    <ListView  android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:clipToPadding="false" android:paddingTop="16dp" >    </ListView></LinearLayout>

再看效果

更多相关文章

  1. Android(安卓)音视频开发(五) : OpenGL ES API,了解 OpenGL 开发
  2. Android核心功能
  3. Android(安卓)studio相对布局的常用属性
  4. android:layout_weight属性详解
  5. 深入android
  6. android 控件布局(顶部、底部......) 留着自己用
  7. Android(安卓)UI控件之ToggleButton、Switch
  8. Android流式布局实现
  9. android 各种控件颜色值的设置(使用Drawable,Color)

随机推荐

  1. 【mysql 优化 5】左连接和右连接优化
  2. 数据库相关零散知识点记录
  3. mysql 反向生成 er图
  4. 用过mysql存储过程和oracle存储过程的哥
  5. mysql 拷贝表(复制表)的几种方式
  6. [mysql] 一次sql耗时高引发报警的分析和
  7. MySQL 慢查询日志分析及可视化结果
  8. MySQL 自定义函数.txt
  9. 救急~mysql无法启动,显示[ERROR] Aborting
  10. MySQL 绿色版基本设置语句