android 较高版本,页面分割线实现LinearLayoutCompat布局简单事例

简介:

转载请注明出处:王亟亟的大牛之路

以前,我们如果要对一个界面切割,分成各个部分可能需要画好多个Layout然后include进来或者用个什么空白的ImageView去填充。V7包中有了一个更简便的实现
包结构:

这里写图片描述
就2个按钮分别去到2个不能布局方式的layout,呈现样式不贴了,因为一模一样。。

要是使用LinearLayoutCompat的话需要引入compile 'com.android.support:appcompat-v7:22.2.1'
eclipse的话去搜刮jar包就好

OneActivity的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/background_material_dark"
        android:layout_weight="1"></LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/linearlayout_compat"></LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/material_blue_grey_800"
        android:layout_weight="1"></LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/linearlayout_compat"></LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/secondary_text_disabled_material_light"
        android:layout_weight="1"></LinearLayout>
</LinearLayout>

这还是简单的布局复杂的呢?一大堆LinearLayout

TwoActivity

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.LinearLayoutCompat  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal" android:layout_width="match_parent"
    app:divider="@drawable/linearlayout_compat"
    app:showDividers="middle"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:background="#0f0000"
        android:gravity="center"
        android:orientation="horizontal" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:background="#e22f00"
        android:gravity="center" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:background="#0000ff"
        android:gravity="center" />
</android.support.v7.widget.LinearLayoutCompat >

只需要引入xmlns:app=”http://schemas.android.com/apk/res-auto”
就可以使用他的一些方法了。
app:divider分割线的素材
app:showDividers呈现方式
以及padding等。

源码地址:http://yunpan.cn/cmvYCnaU4BnzS 访问密码 1b7e

目录
相关文章
|
1月前
|
Android开发
Android实现页面渐变效果
Android实现页面渐变效果
22 1
|
1月前
|
XML Android开发 数据格式
android点击FrameLayout、LinearLayout等父布局没响应的原因以及解决方案
android点击FrameLayout、LinearLayout等父布局没响应的原因以及解决方案
32 2
|
1月前
|
编解码 Android开发
Android获取设备各项信息(设备id、ip地址、设备名称、运行商、品牌、型号、分辨率、处理器、国家码、系统语言、网络类型、oaid、android版本、操作系统版本、mac地址、应用程序签名..)1
Android获取设备各项信息(设备id、ip地址、设备名称、运行商、品牌、型号、分辨率、处理器、国家码、系统语言、网络类型、oaid、android版本、操作系统版本、mac地址、应用程序签名..)
62 1
|
1月前
|
XML Android开发 数据格式
Android六大布局
Android六大布局
37 1
|
1月前
|
编解码 开发工具 Android开发
Android获取设备各项信息(设备id、ip地址、设备名称、运行商、品牌、型号、分辨率、处理器、国家码、系统语言、网络类型、oaid、android版本、操作系统版本、mac地址、应用程序签名..)2
Android获取设备各项信息(设备id、ip地址、设备名称、运行商、品牌、型号、分辨率、处理器、国家码、系统语言、网络类型、oaid、android版本、操作系统版本、mac地址、应用程序签名..)2
37 2
|
2天前
|
开发框架 搜索推荐 .NET
Android之ListActivity 布局与数据绑定
Android之ListActivity 布局与数据绑定
|
2天前
|
Android开发 容器
Android Layout 布局
Android Layout 布局
|
3天前
|
搜索推荐 Android开发
自定义Android标题栏TitleBar布局
自定义Android标题栏TitleBar布局
|
3天前
|
XML Android开发 数据格式
Android五大布局对象---FrameLayout,LinearLayout ,Absolute
Android五大布局对象---FrameLayout,LinearLayout ,Absolute
|
5天前
|
Shell 开发工具 Android开发
android 修改kernel编译版本信息
android 修改kernel编译版本信息
13 0