Android开发优化之——对界面UI的优化(2)
在一个应用程序中,一般都会存在多个Activity,每个Activity对应着一个UI布局文件。一般来说,为了保持不同窗口之间的风格统一,在这些UI布局文件中,几乎肯定会用到很多相同的布局。如果我们在每个xml文件中都把相同的布局都重写一遍,一个是代码冗余,可读性很差;另一个是修改起来比较麻烦,对后期的修改和维护非常不利。所以,一般情况下,我们需要把相同布局的代码单独写成一个模块,然后在用到的时候,可以通过<include /> 标签来重用layout的代码。
常见的,有的应用在最上方会有一个标题栏。类似下图所示。
图 标题栏的示例
如果项目中大部分Activity的布局都包含这样的标题栏,就可以把标题栏的布局单独写成一个xml文件。
<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开发,青软培训