zoukankan      html  css  js  c++  java
  • 开发总结1:

    项目UI总结


    今天整理了一天的项目UI,为了更接近当初的原型设计和UI美工这边给我的效果图。进行了一天的项目重构和代码优化。


    类似于更多的列表item

    这里写图片描述
    通常我们在开发中,常用的是提取一个通用的item 作为一个模板,然后使用adapter,进行数据适配。如果这仅仅是一个固定数目的列表。我们可能会使用线性布局LinearLayout,然后放置若干条子布局,此时,有一个问题出来了,如果,有很多个这种布局相同的菜单出现在这个App中,这时,还能像我这样写但一个一个item代码吗?

     <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:background="#ffebe6"
                android:gravity="center"
                android:visibility="gone"
                android:id="@+id/position_bar"
                android:orientation="vertical">
    
                <TextView
                    android:layout_width="wrap_content"
                                   android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:drawableLeft="@drawable/tips_icon"
                    android:drawablePadding="8dp"
                    android:gravity="center"
                    android:text="保证金不足,请及时追加"
                    android:textColor="#333333"
                    android:textSize="12sp" />
    
            </LinearLayout>

    如果项目中仅有两三处这么写,或许还无可厚非,如果我这里的列表在 A Activity 中有8 个,B Activity 中有 8个或者其他中还有更多,那么这个时候,就应该思考是否要重构你的代码了。这时android 中 的Style 就应该考虑让它出场了。于是我用Android studio 的自动extract 功能重构了一个Style ,并让IDE帮我替换全工程中这种大量的复用代码 。

    <style name="position_tile_item">
            <item name="android:layout_width">wrap_content</item>
            <item name="android:layout_height">wrap_content</item>
            <item name="android:drawableLeft">@drawable/red_dot</item>
            <item name="android:drawablePadding">3dp</item>
            <item name="android:textSize">12sp</item>
            <item name="android:textColor">#333333</item>
            <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
        </style>

    这是我IDE帮我重构的一个Style之后,我在后面需要用的部分,全部直接引用Style即可。
    后面我的代码就变的更加精简。如下

     <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginLeft="15dp"
                            android:layout_weight="1"
                            android:gravity="center_vertical"
                            android:orientation="horizontal">
    
                            <TextView
                                style="@style/position_tile_item"
                                android:text="份额:" />
    
                            <TextView
    
                                style="@style/positin_title2_style"
                                android:text="9891315.65" />
    
                            <TextView
    
                                style="@style/position_title3_item"
                                android:text="元" />
                        </LinearLayout>

    或许,看到这里,其实,这篇文章,并没有讲述一个什么高深方法。


      这篇文章的目的:
    
    • 整理我的日常项目总结,学习笔记。
    • 发布笔记,我的技术感想
    • 撰写发布一下学习心得
    • 为自己平时自己伸手党开始悔改,为开源贡献自己的一点力量。

    版权声明:本文为博主原创文章,未经博主允许不得转载。(转载请注明出自 AllenCoder)

  • 相关阅读:
    rest_framework viewsets.ViewSet 的简单使用
    rest_framework django 简单使用(数据库创建数据, 覆盖数据, 其他的大同小异)
    mysql 初始 密码
    centos python No module named '_bz2'
    shell 中的 if-elif-else 注意点
    CENTOS7下安装REDIS
    centos python安装 No module named '_ctypes'
    编译nginx时struct crypt_data’没有名为‘current_salt’的成员:cd.current_salt[0] = ~salt[0];的解决方案
    centos opencv-python libSM.so.6: cannot open shared object file: No such file or directory
    mysql_config not found
  • 原文地址:https://www.cnblogs.com/allencoder/p/4830742.html
Copyright © 2011-2022 走看看