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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值