源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

解析Android开发优化之:对界面UI的优化详解(二)

  • 时间:2020-05-15 12:43 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:解析Android开发优化之:对界面UI的优化详解(二)
    如果我们在每个xml文件中都把相同的布局都重写一遍,一个是代码冗余,可读性很差;另一个是修改起来比较麻烦,对后期的修改和维护非常不利。所以,一般情况下,我们需要把相同布局的代码单独写成一个模块,然后在用到的时候,可以通过<include /> 标签来重用layout的代码。 [b]常见的,有的应用在最上方会有一个标题栏。类似下图所示。[/b] [img]http://files.jb51.net/file_images/article/201305/201305090923022.jpg[/img] 图 标题栏的示例       如果项目中大部分Activity的布局都包含这样的标题栏,就可以把标题栏的布局单独写成一个xml文件。
[u]复制代码[/u] 代码如下:
<RelativeLayout
    android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:gravity="center"     android:background="@drawable/navigator_bar_bg"     xmlns:android="http://schemas.android.com/apk/res/android">     <TextView         android:id="@android:id/title"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_centerVertical="true"         android:gravity="center"         android:hint="title"         android:textAppearance="?android:attr/textAppearanceMedium" />     <ImageView         android:id="@android:id/closeButton"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentRight="true"         android:src="@drawable/close" /> </RelativeLayout>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部