Android应用开发-小巫CSDN博客客户端UI篇

「爱情、让人受尽委屈。」 2022-08-12 01:18 217阅读 0赞

Android应用开发-小巫CSDN博客客户端UI篇

上一篇是给童鞋们介绍整个项目的概况,从这篇博文开始,后续也会详细介绍整个客户端的开发,但不会贴很多代码,我会贴核心代码然后提供实现思路,想看里面更详细的代码的可以到我的资源页下载源码进行查看,之前上传到github的少了些jar包,所以我在csdn下载频道也上传了一份,地址:http://download.csdn.net/detail/wwj_748/7912513。

整个客户端的开始,自然是需要搭建一个承载我们数据的框架,我这里所说的是UI框架,我们需要事先设计好如何展示我们的内容,有哪些页面,每个页面之间的跳转是怎样的,我们把这些想好之后就可以进行UI界面的设计和实现了。Android中提供了两种实现布局的方法,一种是XML,一种是以代码,前者实现比较容易实现,只需要开发者知道如何布局控件就行,后者需要开发者有较好的灵活性和逻辑。如果不是实现动态布局的话,我们一般会以XML的形式实现布局。

小巫的这个客户端界面不算复杂,界面也算比较简洁。

20140914103858566

(图1-启动页)

20140914103646527

(图2-博文列表)

20140914103534421

(图3-侧边栏)

20140914103839206

(图4-博文详细内容)

20140914104045644

(图5-博文评论列表)

以上给大家展示的是小巫CSDN博客客户端的主要界面效果,下面来讲解如何布局这样的界面:

启动界面布局

/BlogClient/res/layout/splash.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@drawable/splash" >
  6. </RelativeLayout>

说明:启动界面就只是简单一个布局,设置背景图片即可。

主布局-页面切换

/BlogClient/res/layout/main_tab.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@color/wangyibg2"
  6. android:orientation="vertical" >
  7. <!-- 包含头部 -->
  8. <include layout="@layout/main_head" />
  9. <!-- 页面指示器 -->
  10. <com.viewpagerindicator.TabPageIndicator
  11. android:id="@+id/indicator"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:background="@color/transparentblue" />
  15. <!-- 页面切换器 -->
  16. <android.support.v4.view.ViewPager
  17. android:id="@+id/pager"
  18. android:layout_width="match_parent"
  19. android:layout_height="0dp"
  20. android:layout_weight="1" />
  21. </LinearLayout>

说明:这里用到了include标签,这个标签是用来包含布局模块的,可以减少代码冗余,其他界面想使用同样的布局的时候就不用重复写代码了,可读性也比较好。TabPageIndicator是自定义控件,项目中需要引入viewPagerlibrary这个库,它是与ViewPager配套使用,可以实现标签指示,可以实现标签切换页面和滑动切换页面,比较实用的一个组合。

/BlogClient/res/layout/main_head.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:background="@color/light_blue"
  6. android:orientation="horizontal" >
  7. <!-- 自定义控件圆形ImageView -->
  8. <com.xiaowu.blogclient.view.CircleImageView
  9. android:id="@+id/head_icon"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:layout_gravity="center_vertical"
  13. android:layout_marginLeft="8dp"
  14. android:layout_marginRight="4dp"
  15. android:src="@drawable/xiaowu" />
  16. <!-- 分割线 -->
  17. <ImageView
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:layout_gravity="center_vertical"
  21. android:layout_marginLeft="4dp"
  22. android:layout_marginRight="4dp"
  23. android:src="@drawable/base_action_bar_back_divider" />
  24. <!-- 头部文本 -->
  25. <TextView
  26. android:id="@+id/headTV"
  27. android:layout_width="0dp"
  28. android:layout_height="wrap_content"
  29. android:layout_gravity="center_vertical"
  30. android:layout_marginLeft="4dp"
  31. android:layout_weight="1"
  32. android:text="小巫CSDN博客"
  33. android:textColor="@color/white"
  34. android:textSize="21sp"
  35. android:textStyle="bold" >
  36. </TextView>
  37. <ImageButton
  38. android:id="@+id/personCenter"
  39. android:layout_width="wrap_content"
  40. android:layout_height="wrap_content"
  41. android:layout_gravity="center_vertical"
  42. android:background="@drawable/base_action_bar_action_more_selector"
  43. android:visibility="invisible" />
  44. </LinearLayout>

说明:头部的布局没啥可说的,就只是用到了一个圆形的imageView,也是自定义控件的使用。

侧边栏布局

/BlogClient/res/layout/person_center.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:background="@color/wangyibg" >
  7. <ImageView
  8. android:id="@+id/background_img"
  9. android:layout_width="match_parent"
  10. android:layout_height="300dp"
  11. android:layout_marginTop="-100dp"
  12. android:contentDescription="@null"
  13. android:scaleType="fitXY"
  14. android:src="@drawable/scrollview_header" />
  15. <com.xiaowu.blogclient.view.PullScrollView
  16. android:id="@+id/scroll_view"
  17. android:layout_width="match_parent"
  18. android:layout_height="match_parent"
  19. android:fillViewport="true"
  20. app:headerHeight="300dp"
  21. app:headerVisibleHeight="100dp" >
  22. <LinearLayout
  23. android:layout_width="match_parent"
  24. android:layout_height="match_parent"
  25. android:background="@color/transparent"
  26. android:orientation="vertical" >
  27. <LinearLayout
  28. android:layout_width="match_parent"
  29. android:layout_height="wrap_content"
  30. android:layout_marginBottom="10dp"
  31. android:layout_marginTop="5dp"
  32. android:orientation="vertical" >
  33. <com.xiaowu.blogclient.view.CircleImageView
  34. xmlns:app="http://schemas.android.com/apk/res-auto"
  35. android:id="@+id/profile_image"
  36. android:layout_width="96dp"
  37. android:layout_height="96dp"
  38. android:layout_gravity="center_horizontal"
  39. android:src="@drawable/wwj_748"
  40. app:border_color="#FFffffff"
  41. app:border_width="1dp" />
  42. <TextView
  43. android:layout_width="wrap_content"
  44. android:layout_height="wrap_content"
  45. android:layout_gravity="center_horizontal"
  46. android:layout_marginTop="4dp"
  47. android:text="IT_xiao小巫"
  48. android:textColor="@color/white"
  49. android:textSize="18sp"
  50. android:textStyle="bold" />
  51. <ImageView
  52. android:layout_width="wrap_content"
  53. android:layout_height="wrap_content"
  54. android:layout_gravity="center_horizontal"
  55. android:layout_marginTop="4dp"
  56. android:background="@color/transparent"
  57. android:src="@drawable/ico_expert" />
  58. </LinearLayout>
  59. <ImageView
  60. android:layout_width="wrap_content"
  61. android:layout_height="wrap_content"
  62. android:layout_gravity="center_horizontal"
  63. android:src="@drawable/biz_pc_account_line"
  64. android:visibility="invisible" />
  65. <LinearLayout
  66. android:layout_width="match_parent"
  67. android:layout_height="wrap_content"
  68. android:layout_marginTop="20dp"
  69. android:orientation="horizontal" >
  70. <TextView
  71. android:layout_width="wrap_content"
  72. android:layout_height="wrap_content"
  73. android:layout_marginLeft="5dp"
  74. android:text="勋章:"
  75. android:textColor="@color/black"
  76. android:textSize="16sp" />
  77. <com.xiaowu.blogclient.view.CircleImageView
  78. xmlns:app="http://schemas.android.com/apk/res-auto"
  79. android:layout_width="wrap_content"
  80. android:layout_height="wrap_content"
  81. android:layout_marginLeft="5dp"
  82. android:background="@null"
  83. android:src="@drawable/columnstar_s"
  84. app:border_color="#FFffffff"
  85. app:border_width="1dp" />
  86. <com.xiaowu.blogclient.view.CircleImageView
  87. xmlns:app="http://schemas.android.com/apk/res-auto"
  88. android:layout_width="wrap_content"
  89. android:layout_height="wrap_content"
  90. android:layout_marginLeft="5dp"
  91. android:background="@null"
  92. android:src="@drawable/holdon_s"
  93. app:border_color="#FFffffff"
  94. app:border_width="1dp" />
  95. </LinearLayout>
  96. <RelativeLayout
  97. android:layout_width="match_parent"
  98. android:layout_height="wrap_content"
  99. android:layout_marginTop="10dp"
  100. android:gravity="center_horizontal"
  101. android:orientation="vertical" >
  102. <TextView
  103. android:id="@+id/tv1"
  104. android:layout_width="wrap_content"
  105. android:layout_height="wrap_content"
  106. android:text="访问:656748次"
  107. android:textColor="@color/black"
  108. android:textSize="16sp" />
  109. <TextView
  110. android:id="@+id/tv2"
  111. android:layout_width="wrap_content"
  112. android:layout_height="wrap_content"
  113. android:layout_alignLeft="@+id/tv1"
  114. android:layout_below="@+id/tv1"
  115. android:gravity="left"
  116. android:text="积分:12296分"
  117. android:textColor="@color/black"
  118. android:textSize="16sp" />
  119. <TextView
  120. android:id="@+id/tv3"
  121. android:layout_width="wrap_content"
  122. android:layout_height="wrap_content"
  123. android:layout_alignLeft="@+id/tv2"
  124. android:layout_below="@+id/tv2"
  125. android:text="排名:第281名"
  126. android:textColor="@color/black"
  127. android:textSize="16sp" />
  128. </RelativeLayout>
  129. <ImageView
  130. android:layout_width="wrap_content"
  131. android:layout_height="wrap_content"
  132. android:layout_gravity="center_horizontal"
  133. android:layout_marginTop="5dp"
  134. android:src="@drawable/biz_pc_account_line" />
  135. <RelativeLayout
  136. android:layout_width="match_parent"
  137. android:layout_height="wrap_content"
  138. android:layout_marginTop="10dp"
  139. android:gravity="center_horizontal"
  140. android:orientation="vertical" >
  141. <TextView
  142. android:id="@+id/tv4"
  143. android:layout_width="wrap_content"
  144. android:layout_height="wrap_content"
  145. android:text="原创:526篇"
  146. android:textColor="@color/black"
  147. android:textSize="16sp" />
  148. <TextView
  149. android:id="@+id/tv5"
  150. android:layout_width="wrap_content"
  151. android:layout_height="wrap_content"
  152. android:layout_marginLeft="5dp"
  153. android:layout_toRightOf="@+id/tv4"
  154. android:gravity="left"
  155. android:text="转载:81篇"
  156. android:textColor="@color/black"
  157. android:textSize="16sp" />
  158. <TextView
  159. android:id="@+id/tv6"
  160. android:layout_width="wrap_content"
  161. android:layout_height="wrap_content"
  162. android:layout_alignLeft="@+id/tv4"
  163. android:layout_below="@+id/tv4"
  164. android:text="译文:2篇"
  165. android:textColor="@color/black"
  166. android:textSize="16sp" />
  167. <TextView
  168. android:id="@+id/tv7"
  169. android:layout_width="wrap_content"
  170. android:layout_height="wrap_content"
  171. android:layout_below="@+id/tv5"
  172. android:layout_marginLeft="5dp"
  173. android:layout_toRightOf="@+id/tv6"
  174. android:text="评论:956条"
  175. android:textColor="@color/black"
  176. android:textSize="16sp" />
  177. </RelativeLayout>
  178. <ImageView
  179. android:layout_width="wrap_content"
  180. android:layout_height="wrap_content"
  181. android:layout_gravity="center_horizontal"
  182. android:layout_marginTop="5dp"
  183. android:src="@drawable/biz_pc_account_line" />
  184. <RelativeLayout
  185. android:id="@+id/checkUpdateView"
  186. android:layout_width="match_parent"
  187. android:layout_height="40dp"
  188. android:background="@drawable/list_selector" >
  189. <TextView
  190. android:id="@+id/tv8"
  191. android:layout_width="wrap_content"
  192. android:layout_height="wrap_content"
  193. android:layout_centerInParent="true"
  194. android:layout_marginLeft="20dp"
  195. android:text="检查更新"
  196. android:textColor="@color/black"
  197. android:textSize="18sp" />
  198. <ImageView
  199. android:layout_width="wrap_content"
  200. android:layout_height="wrap_content"
  201. android:layout_alignParentRight="true"
  202. android:layout_centerVertical="true"
  203. android:layout_marginRight="5dp"
  204. android:focusable="false"
  205. android:src="@drawable/app_recommend_arrow" />
  206. </RelativeLayout>
  207. <ImageView
  208. android:layout_width="wrap_content"
  209. android:layout_height="wrap_content"
  210. android:layout_gravity="center_horizontal"
  211. android:src="@drawable/biz_pc_account_line" />
  212. <RelativeLayout
  213. android:id="@+id/shareView"
  214. android:layout_width="match_parent"
  215. android:layout_height="40dp"
  216. android:background="@drawable/list_selector" >
  217. <TextView
  218. android:id="@+id/tv9"
  219. android:layout_width="wrap_content"
  220. android:layout_height="wrap_content"
  221. android:layout_centerInParent="true"
  222. android:layout_marginLeft="20dp"
  223. android:text="分享好友"
  224. android:textColor="@color/black"
  225. android:textSize="18sp" />
  226. <ImageView
  227. android:layout_width="wrap_content"
  228. android:layout_height="wrap_content"
  229. android:layout_alignParentRight="true"
  230. android:layout_centerVertical="true"
  231. android:layout_marginRight="5dp"
  232. android:focusable="false"
  233. android:src="@drawable/app_recommend_arrow" />
  234. </RelativeLayout>
  235. <ImageView
  236. android:layout_width="wrap_content"
  237. android:layout_height="wrap_content"
  238. android:layout_gravity="center_horizontal"
  239. android:src="@drawable/biz_pc_account_line" />
  240. <RelativeLayout
  241. android:id="@+id/aboutView"
  242. android:layout_width="match_parent"
  243. android:layout_height="40dp"
  244. android:background="@drawable/list_selector" >
  245. <TextView
  246. android:id="@+id/tv10"
  247. android:layout_width="wrap_content"
  248. android:layout_height="wrap_content"
  249. android:layout_centerInParent="true"
  250. android:layout_marginLeft="20dp"
  251. android:text="关于"
  252. android:textColor="@color/black"
  253. android:textSize="18sp" />
  254. <ImageView
  255. android:layout_width="wrap_content"
  256. android:layout_height="wrap_content"
  257. android:layout_alignParentRight="true"
  258. android:layout_centerVertical="true"
  259. android:layout_marginRight="5dp"
  260. android:focusable="false"
  261. android:src="@drawable/app_recommend_arrow" />
  262. </RelativeLayout>
  263. <ImageView
  264. android:layout_width="wrap_content"
  265. android:layout_height="wrap_content"
  266. android:layout_gravity="center_horizontal"
  267. android:src="@drawable/biz_pc_account_line" />
  268. <Button
  269. android:id="@+id/showSpot"
  270. android:layout_width="fill_parent"
  271. android:layout_height="wrap_content"
  272. android:background="@drawable/list_selector"
  273. android:text="展示插播广告" />
  274. <ImageView
  275. android:layout_width="wrap_content"
  276. android:layout_height="wrap_content"
  277. android:layout_gravity="center_horizontal"
  278. android:src="@drawable/biz_pc_account_line" />
  279. <RelativeLayout
  280. android:id="@+id/adLayout"
  281. android:layout_width="fill_parent"
  282. android:layout_height="wrap_content"
  283. android:gravity="center_horizontal" >
  284. </RelativeLayout>
  285. </LinearLayout>
  286. </com.xiaowu.blogclient.view.PullScrollView>
  287. </RelativeLayout>

说明:侧边栏使用的是SlidingMenu——侧滑菜单,也是需要包含这个库。这里要提一下的是,使用到了有下拉回弹效果的ScrollView,一个自定义控件,在小巫的手机里效果还是可以的,在分辨率小的手机可能效果没那么好。

博文列表布局

/BlogClient/res/layout/article_list_layout.xml

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@color/wangyibg"
  6. tools:context=".MainFrag" >
  7. <!-- 开源控件,具有顶部下拉和底部上拉刷新的效果 -->
  8. <me.maxwin.view.XListView
  9. android:id="@+id/blogListView"
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent"
  12. android:cacheColorHint="#00000000"
  13. android:divider="@drawable/base_list_divider_drawable"
  14. android:fadingEdge="none"
  15. />
  16. <LinearLayout
  17. android:id="@+id/noBlogLayout"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:layout_centerInParent="true"
  21. android:visibility="invisible">
  22. <ImageView
  23. android:id="@+id/no_blog"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:clickable="true"
  27. android:src="@drawable/phiz"
  28. android:visibility="visible" />
  29. <TextView
  30. android:id="@+id/tv_noblog"
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"
  33. android:text="博主还未发表文章,敬请期待!!!"/>
  34. </LinearLayout>
  35. </RelativeLayout>

博文列表项布局

/BlogClient/res/layout/article_list_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:orientation="vertical"
  6. android:paddingBottom="8dp"
  7. android:paddingLeft="16dp"
  8. android:paddingRight="16dp"
  9. android:paddingTop="8dp" >
  10. <TextView
  11. android:id="@+id/title"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:layout_marginBottom="8dp"
  15. android:text="Cocos2d-x 3.2示例UserDefaultTest(用户默认配置)"
  16. android:textColor="@color/black"
  17. android:textSize="18sp"
  18. android:textStyle="bold" />
  19. <LinearLayout
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content"
  22. android:baselineAligned="true"
  23. android:orientation="horizontal" >
  24. <ImageView
  25. android:id="@+id/blogImg"
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"
  28. android:layout_marginRight="8dp"
  29. android:src="@drawable/csdn"
  30. android:visibility="visible" />
  31. <TextView
  32. android:id="@+id/content"
  33. android:layout_width="match_parent"
  34. android:layout_height="wrap_content"
  35. android:ellipsize="end"
  36. android:singleLine="false"
  37. android:maxLines="4"
  38. android:text="本篇博客介绍Cocos2d-x 3.2示例中的UserDefaulstTest,我们在开发中可能需要用到一些默认配置,一般会以xml形式保存。Cocos2d-x为我们提供了UserDefault类来实现这样的需求。"
  39. android:textColor="@color/nomalGray"
  40. android:textSize="14sp" />
  41. </LinearLayout>
  42. <LinearLayout
  43. android:layout_width="match_parent"
  44. android:layout_height="wrap_content"
  45. android:gravity="center_vertical" >
  46. <TextView
  47. android:id="@+id/date"
  48. android:layout_width="0dp"
  49. android:layout_height="wrap_content"
  50. android:layout_weight="1"
  51. android:gravity="center_vertical|right"
  52. android:paddingTop="8dp"
  53. android:singleLine="true"
  54. android:text="2014-08-08 17:54|141人阅读"
  55. android:textColor="@color/nomalGray"
  56. android:textSize="12sp" />
  57. <TextView
  58. android:id="@+id/id"
  59. android:layout_width="0dp"
  60. android:layout_height="wrap_content"
  61. android:layout_weight="1"
  62. android:gravity="right"
  63. android:paddingTop="16dp"
  64. android:text="1"
  65. android:textColor="@color/nomalGray"
  66. android:visibility="gone" />
  67. </LinearLayout>
  68. </LinearLayout>

博文详细内容布局

/BlogClient/res/layout/article_detail.xml

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:id="@+id/blogContentView"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@color/wangyibg"
  6. android:clickable="true" >
  7. <RelativeLayout
  8. android:id="@+id/head"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content" >
  11. <include layout="@layout/article_detail_head" />
  12. </RelativeLayout>
  13. <!-- 具有顶部下拉刷新和底部上拉刷新的ListView -->
  14. <me.maxwin.view.XListView
  15. android:id="@+id/listview"
  16. android:layout_width="match_parent"
  17. android:layout_height="match_parent"
  18. android:layout_below="@+id/head"
  19. android:divider="@null" />
  20. <ProgressBar
  21. android:id="@+id/blogContentPro"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:layout_centerInParent="true"
  25. android:indeterminateDrawable="@drawable/progressbar_large"
  26. android:visibility="visible" />
  27. <ImageView
  28. android:id="@+id/reLoadImage"
  29. android:layout_width="wrap_content"
  30. android:layout_height="wrap_content"
  31. android:layout_centerInParent="true"
  32. android:clickable="true"
  33. android:src="@drawable/base_empty_view"
  34. android:visibility="invisible" />
  35. </RelativeLayout>

说明:博文详细内容的布局也是由XListView组成,所以我们可以知道整个布局就是一个ListView,然而ListView的项元素是由不同布局组成。

/BlogClient/res/layout/article_detail_title_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:id="@+id/text"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:paddingLeft="@dimen/activity_horizontal_margin"
  11. android:paddingRight="@dimen/activity_horizontal_margin"
  12. android:paddingTop="16dp"
  13. android:paddingBottom="8dp"
  14. android:gravity="center_vertical"
  15. android:textSize="21sp"
  16. android:textStyle="bold"
  17. android:text="" />
  18. </LinearLayout>

说明:博文详细内容的标题项。

/BlogClient/res/layout/article_detail_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:id="@+id/text"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_gravity="center_horizontal"
  11. android:lineSpacingExtra="8dp"
  12. android:paddingLeft="@dimen/activity_horizontal_margin"
  13. android:paddingRight="@dimen/activity_horizontal_margin"
  14. android:paddingTop="8dp"
  15. android:paddingBottom="8dp"
  16. android:gravity="center_vertical"
  17. android:textSize="15sp"
  18. android:text="" />
  19. </LinearLayout>

说明:博文详细内容的文本项。

/BlogClient/res/layout/article_detail_bold_title_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:id="@+id/text"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:gravity="center_vertical"
  11. android:lineSpacingExtra="8dp"
  12. android:paddingBottom="@dimen/activity_horizontal_margin"
  13. android:paddingLeft="@dimen/activity_horizontal_margin"
  14. android:paddingRight="@dimen/activity_horizontal_margin"
  15. android:paddingTop="@dimen/activity_horizontal_margin"
  16. android:text=""
  17. android:textColor="@color/coffee"
  18. android:textSize="16sp"
  19. android:textStyle="bold" />
  20. </LinearLayout>

说明:博文详细内容粗标题项。

/BlogClient/res/layout/article_detail_img_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <ImageView
  7. android:id="@+id/imageView"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_marginLeft="@dimen/activity_horizontal_margin"
  11. android:layout_marginRight="@dimen/activity_horizontal_margin"
  12. android:layout_marginTop="8dp"
  13. android:layout_marginBottom="8dp"
  14. android:background="@drawable/biz_topic_vote_submit_default"
  15. android:layout_gravity="center_horizontal"/>
  16. </LinearLayout>

说明:博文详细内容的图片项。

/BlogClient/res/layout/article_detail_code_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:orientation="vertical" >
  6. <WebView
  7. android:id="@+id/code_view"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:focusableInTouchMode="true"
  11. android:layout_margin="5dp"
  12. />
  13. </LinearLayout>

说明:博文想详细内容的代码项。

上面关于博文详细内容有多个布局,是整个客户端最复杂的布局了,大家可以好好感受一下。

博文评论列表布局

/BlogClient/res/layout/activity_comment.xml

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:id="@+id/newsContentView"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@color/wangyibg"
  6. android:clickable="true" >
  7. <RelativeLayout
  8. android:id="@+id/head"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content" >
  11. <include layout="@layout/comment_head" />
  12. </RelativeLayout>
  13. <me.maxwin.view.XListView
  14. android:id="@+id/listview"
  15. android:layout_width="match_parent"
  16. android:layout_height="match_parent"
  17. android:layout_below="@+id/head"
  18. android:divider="@drawable/base_list_divider_drawable" />
  19. <ProgressBar
  20. android:id="@+id/newsContentPro"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:layout_centerInParent="true"
  24. android:indeterminateDrawable="@drawable/progressbar_large"
  25. android:visibility="visible" />
  26. <ImageView
  27. android:id="@+id/reLoadImage"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:layout_centerInParent="true"
  31. android:clickable="true"
  32. android:src="@drawable/base_empty_view"
  33. android:visibility="invisible" />
  34. <!--
  35. <ImageView
  36. android:layout_width="fill_parent"
  37. android:layout_height="wrap_content"
  38. android:background="@drawable/base_list_divider_drawable"
  39. />
  40. -->
  41. <!--
  42. <LinearLayout
  43. android:id="@+id/commentEditL"
  44. android:layout_width="match_parent"
  45. android:layout_height="wrap_content"
  46. android:orientation="horizontal"
  47. android:layout_alignParentBottom="true"
  48. android:background="@color/wangyibg"
  49. >
  50. <EditText
  51. android:id="@+id/commentEdit"
  52. android:layout_width="0dp"
  53. android:layout_height="wrap_content"
  54. android:layout_weight="1"
  55. android:drawableLeft="@drawable/biz_news_newspage_comment_icon"
  56. android:textSize="14sp"
  57. android:drawablePadding="8dp"
  58. android:layout_margin="6dp"
  59. android:hint="添加评论"/>
  60. <ImageButton
  61. android:id="@+id/commentSend"
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:background="@drawable/comment_btn"
  65. android:layout_gravity="center_vertical"
  66. android:layout_marginRight="4dp"/>
  67. </LinearLayout>
  68. -->
  69. </RelativeLayout>

说明:评论列表跟博文详细内容的布局类似,也是由XListView组成,只是需要区分评论和回复评论的列表项,区分的逻辑是在代码中实现的,本篇博客之说明布局实现。

/BlogClient/res/layout/comment_head.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:background="@drawable/biz_news_detaila_action_bar_bg"
  6. android:orientation="horizontal" >
  7. <ImageView
  8. android:id="@+id/backBtn"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:layout_gravity="center_vertical"
  12. android:layout_marginLeft="0dp"
  13. android:layout_marginRight="0dp"
  14. android:background="@drawable/back_btn"/>
  15. <ImageView
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:layout_gravity="center_vertical"
  19. android:src="@drawable/base_action_bar_back_divider"/>
  20. <TextView
  21. android:id="@+id/headTV"
  22. android:layout_width="0dp"
  23. android:layout_height="wrap_content"
  24. android:layout_weight="1"
  25. android:layout_gravity="center_vertical"
  26. android:layout_marginLeft="4dp"
  27. android:textColor="@color/white"
  28. android:textStyle="bold"
  29. android:textSize="21sp"
  30. android:text="">
  31. </TextView>
  32. <ProgressBar
  33. android:id="@+id/progress"
  34. android:layout_width="wrap_content"
  35. android:layout_height="wrap_content"
  36. android:layout_gravity="center_vertical"
  37. android:visibility="gone" />
  38. <TextView
  39. android:id="@+id/comment"
  40. android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:layout_gravity="center_vertical"
  43. android:text=""
  44. android:textColor="@color/white"
  45. android:textSize="12sp"
  46. android:layout_marginRight="4dp"
  47. android:gravity="center"
  48. android:background="@drawable/biz_news_detailpage_comment_normal"/>
  49. <!-- <ImageButton
  50. android:id="@+id/personCenter"
  51. android:layout_width="wrap_content"
  52. android:layout_height="wrap_content"
  53. android:layout_gravity="center_vertical"
  54. android:src="@drawable/base_send_normal"
  55. android:background="@drawable/person_btn"
  56. /> -->
  57. </LinearLayout>

说明:评论界面顶部布局。

/BlogClient/res/layout/comment_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:orientation="horizontal"
  6. android:paddingBottom="8dp"
  7. android:paddingLeft="16dp"
  8. android:paddingRight="16dp"
  9. android:paddingTop="8dp" >
  10. <com.xiaowu.blogclient.view.CircleImageView
  11. xmlns:app="http://schemas.android.com/apk/res-auto"
  12. android:id="@+id/userface"
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:background="@drawable/csdn"
  16. app:border_color="#FFffffff"
  17. app:border_width="1dp" />
  18. <LinearLayout
  19. android:layout_width="match_parent"
  20. android:layout_height="wrap_content"
  21. android:layout_marginLeft="5dp"
  22. android:orientation="vertical" >
  23. <TextView
  24. android:id="@+id/name"
  25. android:layout_width="match_parent"
  26. android:layout_height="wrap_content"
  27. android:layout_marginBottom="4dp"
  28. android:layout_marginLeft="5dp"
  29. android:text="username"
  30. android:textColor="@color/light_blue"
  31. android:textSize="14sp" />
  32. <!--
  33. <ImageView
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"
  36. android:background="@drawable/biz_pc_account_line" />
  37. -->
  38. <TextView
  39. android:id="@+id/content"
  40. android:layout_width="match_parent"
  41. android:layout_height="wrap_content"
  42. android:layout_marginLeft="4dp"
  43. android:text="mark"
  44. android:ellipsize="none"
  45. android:singleLine="false"
  46. android:textSize="16sp" />
  47. <LinearLayout
  48. android:layout_width="match_parent"
  49. android:layout_height="wrap_content"
  50. android:layout_marginTop="4dp"
  51. android:orientation="horizontal" >
  52. <TextView
  53. android:id="@+id/replyCount"
  54. android:layout_width="wrap_content"
  55. android:layout_height="wrap_content"
  56. android:gravity="center"
  57. android:text=""
  58. android:textColor="@color/nomalGray"
  59. android:textSize="12sp" />
  60. <TextView
  61. android:id="@+id/date"
  62. android:layout_width="0dp"
  63. android:layout_height="wrap_content"
  64. android:layout_weight="1"
  65. android:gravity="right"
  66. android:text="2013-10-11"
  67. android:textColor="@color/nomalGray"
  68. android:textSize="12sp" />
  69. </LinearLayout>
  70. </LinearLayout>
  71. </LinearLayout>

说明:评论列表的主题项布局。

/BlogClient/res/layout/comment_child_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@color/wangyibg2" >
  6. <ImageView
  7. android:layout_width="match_parent"
  8. android:layout_height="4dp"
  9. android:background="@drawable/shadow_l" />
  10. <TextView
  11. android:id="@+id/replyIcon"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:layout_centerVertical="true"
  15. android:layout_marginLeft="16dp"
  16. android:drawableLeft="@drawable/material_go_normal"
  17. android:gravity="center_vertical"
  18. android:text="回复:"
  19. android:textColor="@color/nomalGray" />
  20. <LinearLayout
  21. android:layout_width="match_parent"
  22. android:layout_height="wrap_content"
  23. android:layout_marginBottom="3dp"
  24. android:layout_marginLeft="16dp"
  25. android:layout_marginRight="16dp"
  26. android:layout_marginTop="3dp"
  27. android:layout_toRightOf="@+id/replyIcon"
  28. android:orientation="vertical" >
  29. <TextView
  30. android:id="@+id/name"
  31. android:layout_width="match_parent"
  32. android:layout_height="wrap_content"
  33. android:layout_marginBottom="4dp"
  34. android:text="username"
  35. android:textColor="@color/light_blue"
  36. android:textSize="12sp" />
  37. <!--
  38. <ImageView
  39. android:layout_width="match_parent"
  40. android:layout_height="wrap_content"
  41. android:background="@drawable/biz_pc_account_line"
  42. />
  43. -->
  44. <TextView
  45. android:id="@+id/content"
  46. android:layout_width="match_parent"
  47. android:layout_height="wrap_content"
  48. android:layout_marginLeft="4dp"
  49. android:text="mark"
  50. android:ellipsize="none"
  51. android:singleLine="false"
  52. android:textColor="@color/black2"
  53. android:textSize="14sp" />
  54. <LinearLayout
  55. android:layout_width="match_parent"
  56. android:layout_height="wrap_content"
  57. android:layout_marginTop="4dp"
  58. android:orientation="horizontal" >
  59. <TextView
  60. android:id="@+id/replyCount"
  61. android:layout_width="wrap_content"
  62. android:layout_height="wrap_content"
  63. android:gravity="center"
  64. android:text=""
  65. android:textColor="@color/coffee"
  66. android:textSize="12sp" />
  67. <TextView
  68. android:id="@+id/date"
  69. android:layout_width="0dp"
  70. android:layout_height="wrap_content"
  71. android:layout_weight="1"
  72. android:gravity="right"
  73. android:text="2013-10-11"
  74. android:textColor="@color/nomalGray"
  75. android:textSize="12sp" />
  76. </LinearLayout>
  77. </LinearLayout>
  78. </RelativeLayout>

说明:评论列表的回复项布局,跟主题项效果不一样,它是呈灰色背景的,来表示回复项。

UI篇总结

关于整个客户端的UI设计实现已经基本上介绍完,详细看来也没有多么复杂,小巫这里用到了很多自定义组件,让整个客户端好看很多。各位初学者可以根据自己的需求定制自己的UI,再整合一些优秀的开源组件,我相信大家一定能设计出简洁美观的界面。

发表评论

表情:
评论列表 (有 0 条评论,217人围观)

还没有评论,来说两句吧...

相关阅读