在上一篇文章中,我们已经完成了数据模型的代码,并且为了测试方便,在类中直接为很多成员变量提供了默认值。接下来,进入到界面部分。

纵观整个界面,可以分成上下两块,一块是顶端的操作条,另一块是占主体的列表框。

先从顶端的操作条开始,在这里,很容易分解成三个部分,左侧的写微博按钮,中间的用户名显示,右侧的刷新按钮。两个按钮的风格是一样的,都是有常规和按下两种状态,这种按钮是非常常用的,我的做法是:

1. 在drawable文件夹下建立两个xml文件,分别对应了两个按钮;

2. 每个xml文件中使用selector标签定义常规状态和选中状态的两个图片资源;

3. 在Activity的布局中使用ImageButton,指定按钮的background为透明,并指定src为刚才定义的两个xml。

下面是这两个xml文件的内容:

view plaincopy to clipboardprint?

view plaincopy to clipboardprint?

在main.xml文件中,进行这一部分的布局,对于这三个界面元素而言,有明确的位置关系,因此采用RelativeLayout合适,内容如下:

view plaincopy to clipboardprint?

android:layout_width="fill_parent"android:layout_height="44dp"

android:background="@drawable/titlebar_lightgray_bg"android:orientation="horizontal">

android:layout_width="wrap_content"android:layout_height="fill_parent"

android:layout_alignParentLeft="true"android:background="@android:color/transparent"

android:src="@drawable/write_button">

android:layout_width="fill_parent"android:layout_height="fill_parent"

android:textColor="@color/black"android:gravity="center"android:textSize="18sp">

android:layout_width="wrap_content"android:layout_height="fill_parent"

android:layout_alignParentRight="true"android:background="@android:color/transparent"

android:src="@drawable/refresh_button">

最后,指定RelativeLayout的background为背景图片即可。

本次用到的图片有:

821888ac10d4454a6699975e1b9f7020.gif060bd81631cba2865c12b204a6440391.gif   

940f96b8ca6efbf434cc0e5aa6ebf6bf.gif   

46463320472284e6f362841b02a395f3.gif

e6cdb88a2dc6b6b5ccd6e8fdf22496a9.gif

【编辑推荐】

【责任编辑:小野 TEL:(010)68476606】

点赞 0

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐