设计一个界面,整个界面包含一个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日常整理(一)---android返回键、Fragment、android分割线、
  2. Android其它新控件
  3. Android实现画虚线的控件
  4. Android:控件的对象修改控件的值
  5. android之datepicker控件用法
  6. Android——按钮类控件
  7. 图片切换
  8. Android 控件抖动效果

随机推荐

  1. Android--为TextView添加边框
  2. Android上的HttpURLConnection
  3. Android学习07-----事件处理(3)监听日期
  4. android之ConnectivityManager简介,网络连
  5. 解决Android横竖屏切换数据丢失问题
  6. Android(安卓)读取raw下的txt文件
  7. 相对布局(RelativeLayout)
  8. 2010.12.15——— android listView 显示
  9. Android(安卓)四大组件Broadcast
  10. Android(安卓)遇坑【2】 - ScrollView 嵌