快速开发框架三、ZBLibrary

巫马修然
2023-12-01

ZBLibrary从TextView、Button、LinearLayout、ListView、ProgressBar等单个View,
到导航栏、跳转Item、输入清除框、Menu等View组合套件,
像自定义Dialog、Activity背景透明这些style也都有,常用的style全部覆盖,总共171个。
使用ZBLibrary中的styles能一行搞定View属性,一键统一配置UI,快速响应界面更改需求,
再也不怕设计师改一大堆界面的宽高、边距、大小、颜色了!
Android开发中大量使用XML代码作为界面的布局,使用styles能大幅精简XML代码。

比如下面这个界面从AlertDialog至PlacePickerWindow有19个样式相同的跳转Item,点击后颜色加深并跳转界面。
使用styles前XML代码是这样的(838行):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/activity_bg"
    android:orientation="vertical"
    android:splitMotionEvents="false" >

    <RelativeLayout
        android:id="@+id/rlDemoMainTopbar"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/topbar_height"
        android:background="@color/topbar_bg"
        android:gravity="center_vertical" >

        <TextView
            android:id="@+id/tvDemoMainReturn"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/topbar_height"
            android:layout_alignParentLeft="true"
            android:background="@drawable/bg_item_to_alpha"
            android:gravity="center"
            android:minWidth="40dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="退出"
            android:textColor="@color/white"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:text="坐标标准库"
            android:textColor="@color/black"
            android:textSize="18sp" />

        <ImageView
            android:id="@+id/ivDemoMainMenu"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/topbar_height"
            android:layout_alignParentRight="true"
            android:background="@drawable/bg_item_to_alpha"
            android:gravity="center"
            android:minHeight="@dimen/topbar_height"
            android:minWidth="40dp"
            android:paddingLeft="8dp"
            android:paddingRight="10dp"
            android:src="@drawable/menu"
            android:textColor="@color/white"
            android:textSize="16sp" />
    </RelativeLayout>

    <ScrollView
        android:id="@+id/svDemoMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/ivDemoMainHead"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_margin="@dimen/common_item_distance"
                android:background="@color/alpha_3"
                android:scaleType="centerCrop" />

            <TextView
                android:id="@+id/tvDemoMainHeadName"
                android:layout_width="match_parent"
                android:layout_height="@dimen/common_item_remind_tv_height"
                android:gravity="center"
                android:text="可点击 选择图片 或 裁剪图片 更改"
                android:textColor="@color/gray_1"
                android:textSize="14sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:paddingBottom="6dp"
                android:paddingTop="30dp"
                android:text="Dialog"
                android:textColor="@color/gray_3"
                android:textSize="@dimen/text_size_big" />

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainAlertDialog"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="AlertDialog"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainItemDialog"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="ItemDialog"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:paddingBottom="6dp"
                android:paddingTop="30dp"
                android:text="Activity"
                android:textColor="@color/gray_3"
                android:textSize="@dimen/text_size_big" />

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainScanActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="ScanActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainSelectPictureActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="SelectPictureActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainCutPictureActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="CutPictureActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainWebViewActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="WebViewActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainEditTextInfoActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="EditTextInfoActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainServerSettingActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="ServerSettingActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:layout_marginBottom="15dp"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="DemoActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoListActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="DemoListActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoFragmentActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="DemoFragmentActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoTabActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="DemoTabActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoTimeRefresherActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="DemoTimeRefresherActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoBroadcastReceiverActivity"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="DemoBroadcastReceiverActivity"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:paddingBottom="6dp"
                android:paddingTop="30dp"
                android:text="Window"
                android:textColor="@color/gray_3"
                android:textSize="@dimen/text_size_big" />

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainTopMenuWindow"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="TopMenuWindow"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainBottomMenuWindow"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="BottomMenuWindow"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainEditTextInfoWindow"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="EditTextInfoWindow"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainDatePickerWindow"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="DatePickerWindow"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:background="@color/alpha_3" />

            <LinearLayout
                android:id="@+id/llDemoMainPlacePickerWindow"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@drawable/bg_white_to_gray"
                android:gravity="center_vertical"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingLeft="@dimen/content_item_left_tv_padding_left"
                android:paddingTop="2dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="left|center"
                    android:paddingRight="@dimen/padding_big"
                    android:singleLine="true"
                    android:text="PlacePickerWindow"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:paddingLeft="@dimen/padding_micro"
                    android:src="@drawable/forward2_light"
                    android:textColor="@color/gray_3"
                    android:textSize="@dimen/text_size_middle" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1px"
                android:layout_marginBottom="30dp"
                android:background="@color/alpha_3" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>


使用styles后XML代码变成了这样(345行,原来的41%):


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/activity_page" >

    <RelativeLayout
        android:id="@+id/rlDemoMainTopbar"
        style="@style/topbar_bg" >

        <TextView
            android:id="@+id/tvDemoMainReturn"
            style="@style/topbar_return_tv"
            android:text="退出" />

        <TextView
            style="@style/topbar_title"
            android:layout_centerHorizontal="true"
            android:text="坐标标准库" />

        <ImageView
            android:id="@+id/ivDemoMainMenu"
            style="@style/topbar_right_btn"
            android:src="@drawable/menu" />
    </RelativeLayout>

    <ScrollView
        android:id="@+id/svDemoMain"
        style="@style/ll_vertical_match_match"
        android:layout_weight="1" >

        <LinearLayout style="@style/ll_vertical_match_match" >

            <ImageView
                android:id="@+id/ivDemoMainHead"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_margin="@dimen/common_item_distance"
                android:background="@color/alpha_3"
                android:scaleType="centerCrop" />

            <TextView
                android:id="@+id/tvDemoMainHeadName"
                android:layout_width="match_parent"
                android:layout_height="@dimen/common_item_remind_tv_height"
                android:gravity="center"
                android:text="可点击 选择图片 或 裁剪图片 更改"
                android:textColor="@color/gray_1"
                android:textSize="14sp" />

            <TextView
                style="@style/text_big"
                android:paddingBottom="6dp"
                android:paddingTop="30dp"
                android:text="Dialog" />

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainAlertDialog"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="AlertDialog" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainItemDialog"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="ItemDialog" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <TextView
                style="@style/text_big"
                android:paddingBottom="6dp"
                android:paddingTop="30dp"
                android:text="Activity" />

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainScanActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="ScanActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainSelectPictureActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="SelectPictureActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainCutPictureActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="CutPictureActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainWebViewActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="WebViewActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainEditTextInfoActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="EditTextInfoActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainServerSettingActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="ServerSettingActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View
                style="@style/divider_horizontal_1px"
                android:layout_marginBottom="15dp" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="DemoActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoListActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="DemoListActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoFragmentActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="DemoFragmentActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoTabActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="DemoTabActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoTimeRefresherActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="DemoTimeRefresherActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainDemoBroadcastReceiverActivity"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="DemoBroadcastReceiverActivity" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <TextView
                style="@style/text_big"
                android:paddingBottom="6dp"
                android:paddingTop="30dp"
                android:text="Window" />

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainTopMenuWindow"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="TopMenuWindow" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainBottomMenuWindow"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="BottomMenuWindow" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainEditTextInfoWindow"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="EditTextInfoWindow" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainDatePickerWindow"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="DatePickerWindow" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View style="@style/divider_horizontal_1px" />

            <LinearLayout
                android:id="@+id/llDemoMainPlacePickerWindow"
                style="@style/content_item_white" >

                <TextView
                    style="@style/content_item_lf_tv"
                    android:layout_weight="1"
                    android:text="PlacePickerWindow" />

                <ImageView style="@style/content_item_rt_img" />
            </LinearLayout>

            <View
                style="@style/divider_horizontal_1px"
                android:layout_marginBottom="30dp" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

顺便推荐下这个网站,输入XML代码后一键生成绑定View的java代码,配合ZBLibrary使用简直太棒了!
http://android.lineten.net/layout.php
ZBLibrary-Android快速开发框架
下载地址(欢迎Star,欢迎Fork)
​https://github.com/TommyLemon/Android-ZBLibrary
下载试用
ZBLibraryDemoApp.apk
转自:www.cnblogs.com/tommylemon/p/5700531.html
 类似资料: