Android (2022 xml版)LinearLayout添加间隔(Divider)的正确姿势

效果图

在这里插入图片描述

最优解

我们直接看最优解

divider_line.xml

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="16dp"
    android:insetTop="4dp"
    android:insetRight="16dp"
    android:insetBottom="4dp">

    <shape>
        <size android:height="1dp"/>
        <solid android:color="#333333"/>
    </shape>

</inset>

使用

<LinearLayout
        android:orientation="vertical"
        android:divider="@drawable/divider_line"
        android:showDividers="middle"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

如果你一下就看懂了,就可以X掉这个网页了。如果想看看还有什么别的方法,可以继续往下看。

方案分析

之前写了Android LinearLayout添加间隔(Divider)的正确姿势
,只能在代码里添加也太low了,so,又用inset的方法写了这篇文章,现在不太喜欢造轮子了。知道思路百度啥都有。不多说了,搞定!


版权声明:本文为qq_35928566原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。