Android LinearLayout 分割线

Android About 2,114 words

原生 divider

<LinearLayout 
    android:divider="?android:dividerHorizontal"
/>

自定义 divider

showDividers是分隔线的显示位置,beginningmiddleend分别代表显示在开始位置,中间,末尾。

<LinearLayout
    android:id="@+id/km_calllog_root_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:divider="@drawable/km_calllog_divider"
    android:orientation="vertical"
    android:showDividers="middle"/>

还有dividerPadding属性这里没有用到,意思很明确给divider添加padding

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <size android:width="1dp"
          android:height="1dp"/>
    <solid android:color="#e1e1e1"/>
</shape>

设置一边距离的padding

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="20dp">
    <shape
        android:shape="rectangle">
        <size
            android:width="1dp"
            android:height="1dp"/>
        <solid android:color="#F2F2F2"/>
    </shape>
</inset>

InsetDrawable

  • 定义这个drawable为InsetDrawable,必须作为根节点。
  • 属性:xmlns:android
    String类型。必须的,定义XML文件的命名空间,必须是 "http://schemas.android.com/apk/res/android".
  • android:drawable
    Drawable 资源 。必须的。引用一个drawable资源
  • android:insetTop
    尺寸。与顶部的距离。可以使一个尺寸值,或者一个尺寸的资源。
  • android:insetRight
    尺寸。与右边的距离。可以使一个尺寸值,或者一个尺寸的资源。
  • android:insetBottom
    尺寸。与底部的距离。可以使一个尺寸值,或者一个尺寸的资源。
  • android:insetLeft
    尺寸。与左边的距离。可以使一个尺寸值,或者一个尺寸的资源。

示例

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/background"
    android:insetTop="10dp"
    android:insetLeft="10dp" />
<?xml version="1.0" encoding="utf-8"?>
<inset
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/drawable_resource"
    android:insetTop="dimension"
    android:insetRight="dimension"
    android:insetBottom="dimension"
    android:insetLeft="dimension" />
Views: 5,161 · Posted: 2019-04-09

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh