LinearLayoutCompat

分析实现的原理:是如何做到给里面的所有child之间添加分割线的。
分析源码我们应该带着目的性去看,可以先给定一个猜想

view的绘制会经过三个方法:onMeasure(测量自身和里面的所有子空间),onLayout(摆放里面的所有子空间),onDraw(绘制)
1)MeasureWidth,MeasureHeight会变大(加上了间隔线);
2)摆放子空间会有一定的体现(childview:left/top/right/bottom);
3)Ondraw绘制的时候也有一定体现(childview:left/top/right/bottom)
附上Android support源码v7下面的widget
LinearLayoutCompat使用

  <android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.spring.demo.MainActivity"
    android:orientation="vertical"
       app:divider="@android:drawable/divider_horizontal_bright"
    app:showDividers="middle"
    app:dividerPadding="25dp"
    android:id="@+id/d">

app:diveider这里用的是系统的,可以用drawable或shape
使用shape的时候一定要添加 ,一定要添加颜色,即使是透明,
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/account_line" />
<size android:height="1px" />
</shape>

app:showDividers = “middle|end|beginning|none”

middle 在每一项中间添加分割线

end 在整体的最后一项添加分割线

beginning 在整体的最上方添加分割线

none 无

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值