在Android 的程序中设置项可以说是一个必须要有的页面。下面说一下如何写一个基本的设置页面。我们先来看一下常用安卓程序的设置页面:


都是大同小异,下面说一下如何实现。其实就是layout的组合,关键是如何去设置图中的圆角。因为大家都知道Android默认的方形的,要想实现圆角就需要我们自己来实现了。方法有很多种,一种实现方法就是做一个背景图片,把图片边角改成圆角的.9.png格式的。如下:


这样的话就比较容易实现了,再看一下整体的Layout布局情况:

xml布局文件如下:注意层次的嵌套。先是一个RelativeLayout,它有两个子布局,RelativeLayout和LinearLayout。

[html] view plain copy
  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/empty_cart_view"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:background="#ffefebe7">
  7. <RelativeLayout
  8. android:id="@+id/top_relative"
  9. android:layout_width="fill_parent"
  10. android:background="#106184"
  11. android:layout_height="50.0dip">
  12. <TextView
  13. android:id="@+id/titleText"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_centerInParent="true"
  17. android:padding="10.0dip"
  18. android:singleLine="true"
  19. android:text="设置"
  20. android:textColor="@color/white"
  21. android:textSize="15dp"/>
  22. </RelativeLayout>
  23. <ScrollView//用来垂直滚动视图,用于设置项较多的情形。如果设置项不多,例如上面的qq,那么就不需要了。
  24. android:layout_width="fill_parent"
  25. android:layout_height="wrap_content"
  26. android:layout_below="@+id/top_relative"
  27. android:fadingEdge="none">
  28. <LinearLayout
  29. android:layout_width="fill_parent"
  30. android:layout_height="wrap_content"
  31. android:gravity="center_vertical"
  32. android:orientation="vertical"
  33. android:paddingBottom="60.0dip"
  34. android:paddingLeft="10.0dip"
  35. android:paddingRight="10.0dip"
  36. android:paddingTop="10.0dip">
  37. <LinearLayout
  38. android:layout_width="fill_parent"
  39. android:layout_height="wrap_content">
  40. <TableLayout
  41. android:id="@+id/MorePageTableLayout_Favorite"
  42. android:layout_width="fill_parent"
  43. android:layout_height="wrap_content"
  44. android:shrinkColumns="0"
  45. android:stretchColumns="0">
  46. <TableRow
  47. android:id="@+id/more_page_row0"
  48. android:layout_width="fill_parent"
  49. android:layout_marginLeft="2.0dip"
  50. android:layout_marginRight="2.0dip"
  51. android:background="@drawable/more_item_press"//.9.png图片圆角的实现。
  52. android:paddingBottom="16.0dip"
  53. android:paddingTop="8.0dip">
  54. <TextView
  55. android:layout_width="wrap_content"
  56. android:layout_height="fill_parent"
  57. android:drawableLeft="@drawable/mylike"
  58. android:drawablePadding="10.0dip"
  59. android:gravity="center_vertical"
  60. android:includeFontPadding="false"
  61. android:paddingLeft="17.0dip"
  62. android:text="我的设置"
  63. android:textColor="#ff333333"
  64. android:textSize="16.0sp"/>
  65. <ImageView
  66. android:layout_width="wrap_content"
  67. android:layout_height="fill_parent"
  68. android:layout_gravity="right"
  69. android:gravity="center_vertical"
  70. android:paddingRight="20.0dip"
  71. android:src="@drawable/ic_arrow"/>
  72. </TableRow>
  73. </TableLayout>
  74. </LinearLayout>
  75. <TextView
  76. android:layout_width="fill_parent"
  77. android:layout_height="wrap_content"
  78. android:layout_marginBottom="10.0dip"
  79. android:layout_marginTop="10.0dip"
  80. android:gravity="center_vertical"
  81. android:paddingLeft="4.0dip"
  82. android:text="我的设置"
  83. android:textColor="#ff888888"
  84. android:textSize="16.0sp"/>
  85. <LinearLayout
  86. android:layout_width="fill_parent"
  87. android:layout_height="wrap_content">
  88. <TableLayout
  89. android:id="@+id/MorePageTableLayout_Follow"
  90. android:layout_width="fill_parent"
  91. android:layout_height="wrap_content"
  92. android:paddingLeft="1.0dip"
  93. android:shrinkColumns="0"
  94. android:stretchColumns="0">
  95. <TableRow
  96. android:id="@+id/more_page_row1"
  97. android:layout_width="fill_parent"
  98. android:layout_marginLeft="2.0dip"
  99. android:layout_marginRight="2.0dip"
  100. android:background="@drawable/more_itemtop_press"
  101. android:paddingBottom="16.0dip"
  102. android:paddingTop="16.0dip">
  103. <TextView
  104. android:layout_width="wrap_content"
  105. android:layout_height="fill_parent"
  106. android:drawableLeft="@drawable/myfollow"
  107. android:drawablePadding="10.0dip"
  108. android:gravity="center_vertical"
  109. android:includeFontPadding="false"
  110. android:paddingLeft="17.0dip"
  111. android:text="账号管理"
  112. android:textColor="#ff333333"
  113. android:textSize="16.0sp"/>
  114. <ImageView
  115. android:layout_width="wrap_content"
  116. android:layout_height="fill_parent"
  117. android:layout_gravity="right"
  118. android:gravity="center_vertical"
  119. android:paddingRight="20.0dip"
  120. android:src="@drawable/ic_arrow"/>
  121. </TableRow>
  122. <TableRow
  123. android:id="@+id/more_page_row2"
  124. android:layout_width="fill_parent"
  125. android:layout_marginLeft="2.0dip"
  126. android:layout_marginRight="2.0dip"
  127. android:background="@drawable/more_itemmiddle_press"
  128. android:paddingBottom="16.0dip"
  129. android:paddingTop="16.0dip">
  130. <TextView
  131. android:layout_width="wrap_content"
  132. android:layout_height="fill_parent"
  133. android:drawableLeft="@drawable/search_friends"
  134. android:drawablePadding="10.0dip"
  135. android:gravity="center_vertical"
  136. android:includeFontPadding="false"
  137. android:paddingLeft="17.0dip"
  138. android:text="个人爱好"
  139. android:textColor="#ff333333"
  140. android:textSize="16.0sp"/>
  141. <ImageView
  142. android:layout_width="wrap_content"
  143. android:layout_height="fill_parent"
  144. android:layout_gravity="right"
  145. android:gravity="center_vertical"
  146. android:paddingRight="20.0dip"
  147. android:src="@drawable/ic_arrow"/>
  148. </TableRow>
  149. <TableRow
  150. android:id="@+id/more_page_row3"
  151. android:layout_width="fill_parent"
  152. android:layout_marginLeft="2.0dip"
  153. android:layout_marginRight="2.0dip"
  154. android:background="@drawable/more_itembottom_press"
  155. android:paddingBottom="16.0dip"
  156. android:paddingTop="16.0dip">
  157. <TextView
  158. android:layout_width="wrap_content"
  159. android:layout_height="fill_parent"
  160. android:drawableLeft="@drawable/invite_friends"
  161. android:drawablePadding="10.0dip"
  162. android:gravity="center_vertical"
  163. android:includeFontPadding="false"
  164. android:paddingLeft="17.0dip"
  165. android:text="浏览记录"
  166. android:textColor="#ff333333"
  167. android:textSize="16.0sp"/>
  168. <ImageView
  169. android:layout_width="wrap_content"
  170. android:layout_height="fill_parent"
  171. android:layout_gravity="right"
  172. android:gravity="center_vertical"
  173. android:paddingRight="20.0dip"
  174. android:src="@drawable/ic_arrow"/>
  175. </TableRow>
  176. </TableLayout>
  177. </LinearLayout>
  178. <TextView
  179. android:layout_width="fill_parent"
  180. android:layout_height="wrap_content"
  181. android:layout_marginBottom="10.0dip"
  182. android:layout_marginTop="10.0dip"
  183. android:gravity="center_vertical"
  184. android:paddingLeft="4.0dip"
  185. android:text="客户端"
  186. android:textColor="#ff888888"
  187. android:textSize="16.0sp"/>
  188. <LinearLayout
  189. android:layout_width="fill_parent"
  190. android:layout_height="wrap_content">
  191. <TableLayout
  192. android:id="@+id/MorePageTableLayout_Client"
  193. android:layout_width="fill_parent"
  194. android:layout_height="wrap_content"
  195. android:paddingLeft="1.0dip"
  196. android:shrinkColumns="0"
  197. android:stretchColumns="0">
  198. <TableRow
  199. android:id="@+id/more_page_row4"
  200. android:layout_width="fill_parent"
  201. android:layout_marginLeft="2.0dip"
  202. android:layout_marginRight="2.0dip"
  203. android:background="@drawable/more_itemtop_press"
  204. android:paddingBottom="16.0dip"
  205. android:paddingTop="16.0dip">
  206. <TextView
  207. android:layout_width="wrap_content"
  208. android:layout_height="fill_parent"
  209. android:drawableLeft="@drawable/setting_mor"
  210. android:drawablePadding="10.0dip"
  211. android:gravity="center_vertical"
  212. android:includeFontPadding="false"
  213. android:paddingLeft="17.0dip"
  214. android:text="设置"
  215. android:textColor="#ff333333"
  216. android:textSize="16.0sp"/>
  217. <ImageView
  218. android:layout_width="wrap_content"
  219. android:layout_height="fill_parent"
  220. android:layout_gravity="right"
  221. android:gravity="center_vertical"
  222. android:paddingRight="20.0dip"
  223. android:src="@drawable/ic_arrow"/>
  224. </TableRow>
  225. <TableRow
  226. android:id="@+id/more_page_row5"
  227. android:layout_width="fill_parent"
  228. android:layout_marginLeft="2.0dip"
  229. android:layout_marginRight="2.0dip"
  230. android:background="@drawable/more_itemmiddle_press"
  231. android:paddingBottom="16.0dip"
  232. android:paddingTop="16.0dip">
  233. <TextView
  234. android:layout_width="wrap_content"
  235. android:layout_height="fill_parent"
  236. android:drawableLeft="@drawable/feed_back"
  237. android:drawablePadding="10.0dip"
  238. android:gravity="center_vertical"
  239. android:includeFontPadding="false"
  240. android:paddingLeft="17.0dip"
  241. android:text="意见反馈"
  242. android:textColor="#ff333333"
  243. android:textSize="16.0sp"/>
  244. <ImageView
  245. android:layout_width="wrap_content"
  246. android:layout_height="fill_parent"
  247. android:layout_gravity="right"
  248. android:gravity="center_vertical"
  249. android:paddingRight="20.0dip"
  250. android:src="@drawable/ic_arrow"/>
  251. </TableRow>
  252. <TableRow
  253. android:id="@+id/more_page_row6"
  254. android:layout_width="fill_parent"
  255. android:layout_marginLeft="2.0dip"
  256. android:layout_marginRight="2.0dip"
  257. android:background="@drawable/more_itemmiddle_press"
  258. android:paddingBottom="16.0dip"
  259. android:paddingTop="16.0dip">
  260. <TextView
  261. android:layout_width="wrap_content"
  262. android:layout_height="fill_parent"
  263. android:drawableLeft="@drawable/moreitems_version"
  264. android:drawablePadding="10.0dip"
  265. android:gravity="center_vertical"
  266. android:includeFontPadding="false"
  267. android:paddingLeft="17.0dip"
  268. android:text="检测更新"
  269. android:textColor="#ff333333"
  270. android:textSize="16.0sp"/>
  271. <ImageView
  272. android:layout_width="wrap_content"
  273. android:layout_height="fill_parent"
  274. android:layout_gravity="right"
  275. android:gravity="center_vertical"
  276. android:paddingRight="20.0dip"
  277. android:src="@drawable/ic_arrow"/>
  278. </TableRow>
  279. <TableRow
  280. android:id="@+id/more_page_row7"
  281. android:layout_width="fill_parent"
  282. android:layout_marginLeft="2.0dip"
  283. android:layout_marginRight="2.0dip"
  284. android:background="@drawable/more_itembottom_press"
  285. android:paddingBottom="16.0dip"
  286. android:paddingTop="16.0dip">
  287. <TextView
  288. android:layout_width="wrap_content"
  289. android:layout_height="fill_parent"
  290. android:drawableLeft="@drawable/about_page_mor"
  291. android:drawablePadding="10.0dip"
  292. android:gravity="center_vertical"
  293. android:includeFontPadding="false"
  294. android:paddingLeft="17.0dip"
  295. android:text="关于"
  296. android:textColor="#ff333333"
  297. android:textSize="16.0sp"/>
  298. <ImageView
  299. android:layout_width="wrap_content"
  300. android:layout_height="fill_parent"
  301. android:layout_gravity="right"
  302. android:gravity="center_vertical"
  303. android:paddingRight="20.0dip"
  304. android:src="@drawable/ic_arrow"/>
  305. </TableRow>
  306. </TableLayout>
  307. </LinearLayout>
  308. </LinearLayout>
  309. </ScrollView>
  310. </RelativeLayout>
看一下效果图:

更多相关文章

  1. iOS 开发者的 Android(安卓)第一课
  2. 最全面的AndroidStudio配置指南总结-包括护眼模式
  3. Android学习随笔之使用限定符
  4. 一文学会所有 Android(安卓)TextView 属性,妈妈再也不担心我的代
  5. Android实验——实验1 用户界面:线性布局
  6. android软键盘上添加一个按钮
  7. android Button设置text属性为字母时,字母自动变成大写
  8. Android(安卓)随机铃声管理器
  9. [Android]用户界面设计

随机推荐

  1. android布局属性详解分享
  2. Android入门篇一:Android(安卓)Activity生
  3. Android布局属性一览表
  4. Android控件属性手册
  5. Android单元测试
  6. Android(安卓)users-permission权限列表
  7. Android之使用ContentResolver对通信录中
  8. Android单例模式
  9. 【Android】保存Bitmap到SD卡
  10. 2011.09.07(5)——— android 跨进程通信之