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

目录
相关文章
|
2天前
|
XML Android开发 数据安全/隐私保护
10. 【Android教程】网格布局 GridLayout
10. 【Android教程】网格布局 GridLayout
9 1
|
2天前
|
Android开发 容器
35. 【Android教程】视频页面:ViewPager
35. 【Android教程】视频页面:ViewPager
14 3
|
2天前
|
Android开发
08. 【Android教程】相对布局 RelativeLayout
08. 【Android教程】相对布局 RelativeLayout
10 0
|
20天前
|
Android开发
Android WindowFeature小探究,Android客户端Web页面通用性能优化实践
Android WindowFeature小探究,Android客户端Web页面通用性能优化实践
|
22天前
|
开发框架 搜索推荐 .NET
Android之ListActivity 布局与数据绑定
Android之ListActivity 布局与数据绑定
16 0
|
2天前
|
开发工具 Android开发 数据安全/隐私保护
12. 【Android教程】绝对布局 AbsoluteLayout
12. 【Android教程】绝对布局 AbsoluteLayout
7 0
|
2天前
|
Android开发
09. 【Android教程】表格布局 TableLayout
09. 【Android教程】表格布局 TableLayout
9 0
|
8天前
|
缓存 监控 Android开发
构建高效Android应用:从优化布局到提升性能
【5月更文挑战第28天】 随着移动设备的普及,用户对Android应用的性能和响应速度有着越来越高的期待。本文旨在探讨一系列实用的技术和策略,帮助开发者在设计阶段就将性能考量纳入其中,以实现流畅和高效的用户体验。我们将深入分析布局优化、内存管理和多线程处理等关键领域,并提出具体的解决方案和最佳实践,以便开发过程中能够有效地避免常见的性能瓶颈。
|
12天前
|
Android开发 容器
安卓和苹果页面和逻辑是否有必要追求百分之百统一
安卓和苹果页面和逻辑是否有必要追求百分之百统一
19 0
|
16天前
|
缓存 编解码 移动开发
构建高效Android应用:从优化布局到提升性能
【5月更文挑战第20天】 在移动开发领域,一个流畅且响应迅速的应用是用户留存的关键。本文将深入探讨如何针对安卓平台优化应用性能,涵盖从布局优化、内存管理到多线程处理等多个方面。我们将通过实例和最佳实践指导开发者避免常见的性能陷阱,并利用现代安卓工具和技巧提高应用的整体效率。