码迷,mamicode.com
首页 > 其他好文 > 详细

对搭档代码的修改意见

时间:2017-03-25 00:56:23      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:activity   tools   height   idt   对齐   ica   文件   ble   XML   

源代码

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     android:paddingBottom="@dimen/activity_vertical_margin"
  4     android:paddingLeft="@dimen/activity_horizontal_margin"
  5     android:paddingRight="@dimen/activity_horizontal_margin"
  6     android:paddingTop="@dimen/activity_vertical_margin"
  7     android:layout_width="match_parent"
  8     android:layout_height="match_parent"
  9     android:orientation="horizontal">
 10 
 11     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 12         xmlns:tools="http://schemas.android.com/tools"
 13         android:layout_width="match_parent"
 14         android:layout_height="match_parent"
 15         android:background="#E1E0DE"
 16         tools:context=".MainActivity">
 17 
 18 
 19 
 20             <RelativeLayout
 21                 android:id="@+id/relativeLayout2"
 22                 android:layout_width="fill_parent"
 23                 android:layout_height="80dp"
 24                 android:layout_alignParentLeft="true"
 25                 android:layout_marginTop="20dp"
 26                 android:background="@color/white"
 27                 android:clickable="true">
 28 
 29                 <ImageView
 30                     android:id="@+id/imageView1"
 31                     android:layout_width="wrap_content"
 32                     android:layout_height="wrap_content"
 33                     android:layout_alignParentLeft="true"
 34                     android:layout_centerVertical="true"
 35                     android:src="@android:drawable/ic_delete" />
 36 
 37                 <TextView
 38                     android:id="@+id/text_pyq"
 39                     android:layout_width="wrap_content"
 40                     android:layout_height="wrap_content"
 41                     android:layout_centerVertical="true"
 42                     android:layout_marginLeft="20dp"
 43                     android:layout_toRightOf="@+id/imageView1"
 44                     android:text="我的id"
 45                     android:textColor="#000" />
 46 
 47                 <TextView
 48                     android:id="@+id/text_pyq1"
 49                     android:layout_width="wrap_content"
 50                     android:layout_height="wrap_content"
 51                     android:layout_below="@+id/text_pyq"
 52                     android:layout_marginLeft="20dp"
 53                     android:layout_toEndOf="@+id/imageView1"
 54                     android:text="微信号"
 55                     android:textColor="#000" />
 56 
 57                 <ImageView
 58                     android:id="@+id/imageView2"
 59                     android:layout_width="wrap_content"
 60                     android:layout_height="wrap_content"
 61                     android:layout_alignParentRight="true"
 62                     android:layout_centerVertical="true"
 63                     android:src="@android:drawable/ic_delete" />
 64 
 65             </RelativeLayout>
 66 
 67 
 68 
 69 
 70         <RelativeLayout
 71             android:id="@+id/relativeLayout3"
 72             android:layout_width="fill_parent"
 73             android:layout_height="100dp"
 74             android:layout_alignParentLeft="true"
 75             android:layout_below="@+id/relativeLayout2"
 76             android:layout_marginTop="20dp"
 77             android:background="@color/white">
 78 
 79             <RelativeLayout
 80                 android:id="@+id/rel_sys"
 81                 android:layout_width="match_parent"
 82                 android:layout_height="50dp"
 83                 android:layout_alignParentLeft="true"
 84                 android:layout_alignParentTop="true"
 85 
 86                 android:clickable="true">
 87 
 88                 <ImageView
 89                     android:id="@+id/imageView3"
 90                     android:layout_width="wrap_content"
 91                     android:layout_height="wrap_content"
 92                     android:layout_alignParentLeft="true"
 93                     android:layout_centerVertical="true"
 94                     android:src="@android:drawable/ic_delete" />
 95 
 96                 <TextView
 97                     android:id="@+id/text_sys"
 98                     android:layout_width="wrap_content"
 99                     android:layout_height="wrap_content"
100                     android:layout_centerVertical="true"
101                     android:layout_marginLeft="20dp"
102                     android:layout_toRightOf="@+id/imageView3"
103                     android:text="相册"
104                     android:textColor="#000" />
105 
106 
107             </RelativeLayout>
108 
109             <View
110                 android:layout_width="match_parent"
111                 android:layout_height="0.5dp"
112                 android:layout_alignBottom="@+id/rel_sys"
113                 android:background="#E1E0DE">
114 
115             </View>
116 
117             <RelativeLayout
118                 android:layout_width="match_parent"
119                 android:layout_height="50dp"
120                 android:layout_alignParentBottom="true"
121                 android:layout_marginRight="-10.5dp"
122 
123                 android:clickable="true">
124 
125                 <ImageView
126                     android:id="@+id/imageView5"
127                     android:layout_width="wrap_content"
128                     android:layout_height="wrap_content"
129                     android:layout_alignParentLeft="true"
130                     android:layout_centerVertical="true"
131                     android:src="@android:drawable/ic_delete" />
132 
133                 <TextView
134                     android:id="@+id/text_yyy"
135                     android:layout_width="wrap_content"
136                     android:layout_height="wrap_content"
137                     android:layout_centerVertical="true"
138                     android:layout_marginLeft="20dp"
139                     android:layout_toRightOf="@+id/imageView5"
140                     android:text="收藏"
141                     android:textColor="#000" />
142 
143 
144             </RelativeLayout>
145         </RelativeLayout>
146 
147         <RelativeLayout
148             android:id="@+id/relativeLayout4"
149             android:layout_width="match_parent"
150             android:layout_height="100dp"
151             android:layout_alignParentLeft="true"
152             android:layout_below="@+id/relativeLayout3"
153             android:layout_marginTop="20dp"
154             android:background="@color/white">
155 
156             <RelativeLayout
157                 android:id="@+id/rel_fjdr"
158                 android:layout_width="match_parent"
159                 android:layout_height="50dp"
160                 android:layout_alignParentLeft="true"
161                 android:layout_alignParentTop="true"
162 
163                 android:clickable="true">
164 
165                 <ImageView
166                     android:id="@+id/imageView7"
167                     android:layout_width="wrap_content"
168                     android:layout_height="wrap_content"
169                     android:layout_alignParentLeft="true"
170                     android:layout_centerVertical="true"
171                     android:src="@android:drawable/ic_delete" />
172 
173                 <TextView
174                     android:id="@+id/text_fjdr"
175                     android:layout_width="wrap_content"
176                     android:layout_height="wrap_content"
177                     android:layout_centerVertical="true"
178                     android:layout_marginLeft="20dp"
179                     android:layout_toRightOf="@+id/imageView7"
180                     android:text="钱包"
181 
182                     android:textColor="#000" />
183 
184 
185             </RelativeLayout>
186 
187             <View
188                 android:layout_width="match_parent"
189                 android:layout_height="0.5dp"
190                 android:layout_alignBottom="@+id/rel_fjdr"
191                 android:background="#E1E0DE">
192 
193             </View>
194 
195             <RelativeLayout
196                 android:layout_width="match_parent"
197                 android:layout_height="50dp"
198                 android:layout_alignParentBottom="true"
199                 android:layout_marginRight="-10.5dp"
200 
201                 android:clickable="true">
202 
203                 <ImageView
204                     android:id="@+id/imageView9"
205                     android:layout_width="wrap_content"
206                     android:layout_height="wrap_content"
207                     android:layout_alignParentLeft="true"
208                     android:layout_centerVertical="true"
209                     android:src="@android:drawable/ic_delete" />
210 
211                 <TextView
212                     android:id="@+id/text_plp"
213                     android:layout_width="wrap_content"
214                     android:layout_height="wrap_content"
215                     android:layout_centerVertical="true"
216                     android:layout_marginLeft="20dp"
217                     android:layout_toRightOf="@+id/imageView9"
218                     android:text="卡包"
219 
220                     android:textColor="#000" />
221 
222 
223             </RelativeLayout>
224         </RelativeLayout>
225 
226         <RelativeLayout
227             android:id="@+id/relativeLayout5"
228             android:layout_width="match_parent"
229             android:layout_height="50dp"
230             android:layout_alignParentLeft="true"
231             android:layout_below="@+id/relativeLayout4"
232             android:layout_marginTop="20dp"
233             android:background="@color/white"
234             android:clickable="true">
235 
236             <ImageView
237                 android:id="@+id/imageView11"
238                 android:layout_width="wrap_content"
239                 android:layout_height="wrap_content"
240                 android:layout_alignParentLeft="true"
241                 android:layout_centerVertical="true"
242                 android:src="@android:drawable/ic_delete" />
243 
244             <TextView
245                 android:id="@+id/text_yxzx"
246                 android:layout_width="wrap_content"
247                 android:layout_height="wrap_content"
248                 android:layout_centerVertical="true"
249                 android:layout_marginLeft="20dp"
250                 android:layout_toRightOf="@+id/imageView11"
251                 android:text="表情"
252                 android:textColor="#000" />
253 
254 
255         </RelativeLayout>
256 
257         <RelativeLayout
258             android:id="@+id/relativeLayout6"
259             android:layout_width="match_parent"
260             android:layout_height="50dp"
261             android:layout_alignParentLeft="true"
262             android:layout_below="@+id/relativeLayout5"
263             android:layout_marginTop="20dp"
264             android:background="@color/white"
265             android:clickable="true">
266 
267             <ImageView
268                 android:id="@+id/imageView12"
269                 android:layout_width="wrap_content"
270                 android:layout_height="wrap_content"
271                 android:layout_alignParentLeft="true"
272                 android:layout_centerVertical="true"
273                 android:src="@android:drawable/ic_delete" />
274 
275             <TextView
276                 android:id="@+id/text_yxzx1"
277                 android:layout_width="wrap_content"
278                 android:layout_height="wrap_content"
279                 android:layout_centerVertical="true"
280                 android:layout_marginLeft="20dp"
281                 android:layout_toRightOf="@+id/imageView12"
282                 android:text="设置"
283                 android:textColor="#000" />
284 
285 
286         </RelativeLayout>
287 
288 
289     </RelativeLayout>
290 
291 
292 </LinearLayout>

通过分析代码,发现了搭档的几点不足:

  1. 在LinearLayout中使用了如下代码:
    1     android:paddingBottom="@dimen/activity_vertical_margin"
    2     android:paddingLeft="@dimen/activity_horizontal_margin"
    3     android:paddingRight="@dimen/activity_horizontal_margin"
    4     android:paddingTop="@dimen/activity_vertical_margin"

    这些代码是用于RelativeLayout相对布局中的,写在这,会增加无用代码。

  2. XML文件并未添加注释,后期阅读会造成困难。
  3. XML文件格式不美观,没有完整对齐。
  4. 直接在XML文件中使用文字,应该将文字单独放在string目录下。
  5. 使用了诸如以下的已经淘汰的用法: 1 android:layout_width="fill_parent" 
  6. 主体框架用的是线性布局,对于安卓设备的兼容性不高。建议更改其他布局方案。

对搭档代码的修改意见

标签:activity   tools   height   idt   对齐   ica   文件   ble   XML   

原文地址:http://www.cnblogs.com/Wwwyyf/p/6614021.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!