码迷,mamicode.com
首页 > Web开发 > 详细

头像图片上传到sd及服务器

时间:2014-10-11 14:13:25      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:des   android   style   blog   http   color   io   os   ar   

首先在AndroidManifest.xml设置权限:

<!-- 传头像 -->
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

在服务器端加入jar包:commons-fileupload-1.3.1.jar,commons-io-2.4.jar

jar包下载地址:http://pan.baidu.com/s/1mg7gPvi

servlet文件:headerPortaitUploadServlet

  1 package com.ghp.servlet;
  2 
  3 import java.io.File;
  4 import java.io.IOException;
  5 import java.io.PrintWriter;
  6 import java.util.Iterator;
  7 import java.util.List;
  8 
  9 import javax.servlet.ServletException;
 10 import javax.servlet.http.HttpServlet;
 11 import javax.servlet.http.HttpServletRequest;
 12 import javax.servlet.http.HttpServletResponse;
 13 
 14 import org.apache.commons.fileupload.DiskFileUpload;
 15 import org.apache.commons.fileupload.FileItem;
 16 
 17 import com.ghp.dao.UsersDao;
 18 
 19 public class headerPortaitUploadServlet extends HttpServlet {
 20 
 21     /**
 22      * Constructor of the object.
 23      */
 24     public headerPortaitUploadServlet() {
 25         super();
 26     }
 27 
 28     /**
 29      * Destruction of the servlet. <br>
 30      */
 31     public void destroy() {
 32         super.destroy(); // Just puts "destroy" string in log
 33         // Put your code here
 34     }
 35 
 36     /**
 37      * The doGet method of the servlet. <br>
 38      *
 39      * This method is called when a form has its tag value method equals to get.
 40      * 
 41      * @param request the request send by the client to the server
 42      * @param response the response send by the server to the client
 43      * @throws ServletException if an error occurred
 44      * @throws IOException if an error occurred
 45      */
 46     public void doGet(HttpServletRequest request, HttpServletResponse response)
 47             throws ServletException, IOException {
 48 
 49         doPost(request, response);
 50     }
 51 
 52     /**
 53      * The doPost method of the servlet. <br>
 54      *
 55      * This method is called when a form has its tag value method equals to post.
 56      * 
 57      * @param request the request send by the client to the server
 58      * @param response the response send by the server to the client
 59      * @throws ServletException if an error occurred
 60      * @throws IOException if an error occurred
 61      */
 62     public void doPost(HttpServletRequest request, HttpServletResponse response)
 63             throws ServletException, IOException {
 64 
 65         response.setContentType("text/html;charset=utf8");
 66         PrintWriter out = response.getWriter();
 67         //临时目录
 68         String temp=request.getSession().getServletContext().getRealPath("/")+"temp";   
 69         //上传文件存放目录
 70         String loadpath=request.getSession().getServletContext().getRealPath("/")+"headerportaitimages"; 
 71         DiskFileUpload fu = new DiskFileUpload();
 72         fu.setSizeMax(1*1024*1024);   // 设置允许用户上传文件大小,单位:字节 
 73         fu.setSizeThreshold(4096);   // 设置最多只允许在内存中存储的数据,单位:字节 
 74         fu.setRepositoryPath(temp); // 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录 
 75         
 76       //开始读取上传信息 
 77         int index=0;
 78         List fileItems = null;                              
 79                              try {
 80                                      fileItems = fu.parseRequest(request);
 81                                       System.out.println("fileItems="+fileItems);
 82                              } catch (Exception e) {
 83                                      e.printStackTrace();
 84                              }
 85                       
 86         // 依次处理每个上传的文件     
 87         Iterator iter = fileItems.iterator(); 
 88         while (iter.hasNext())
 89         {
 90             FileItem item = (FileItem)iter.next();// 忽略其他不是文件域的所有表单信息
 91             if (!item.isFormField())
 92             {
 93                 String img = item.getName();//获取上传文件名,包括路径
 94                 img=img.substring(img.lastIndexOf("\\")+1);//从全路径中提取文件名
 95                 long size = item.getSize();
 96                 if((img==null||img.equals("")) && size==0){
 97                     continue;
 98                 }                     
 99 //                int point = img.indexOf(".");
100 //                img=(new Date()).getTime()+index+img.substring(point,img.length());
101 //                index++;
102                 File fNew= new File(loadpath, img);
103                 try {
104                                      item.write(fNew);
105                              } catch (Exception e) {
106                                      // TODO Auto-generated catch block
107                                      e.printStackTrace();
108                              }
109                 /*int len=img.length();
110                 int length=len-11;
111                 String userName=img.substring(0,length);  
112                 boolean b=UsersDao.updateUsersImg(userName, img);
113                 out.println(b);*/
114                 
115             }else{
116                 //取出不是文件域的所有表单信息
117                 String fieldvalue = item.getString();
118          //如果包含中文应写为:(转为UTF-8编码)
119          //String fieldvalue = new String(item.getString().getBytes(),"UTF-8");
120             }
121         }
122         //response.getOutputStream().print(true);
123         out.println(true);
124         //out.flush();
125         //out.close();
126     }
127 
128     /**
129      * Initialization of the servlet. <br>
130      *
131      * @throws ServletException if an error occurs
132      */
133     public void init() throws ServletException {
134         // Put your code here
135     }
136 
137 }

上传头像图片的activity:PersonnalMessageActivity

  1 package com.ghp.guodouRecipe;
  2 
  3 import java.io.File;
  4 import java.io.FileNotFoundException;
  5 import java.io.FileOutputStream;
  6 import java.io.IOException;
  7 
  8 import com.android.volley.Request.Method;
  9 import com.android.volley.RequestQueue;
 10 import com.android.volley.Response.ErrorListener;
 11 import com.android.volley.Response.Listener;
 12 import com.android.volley.VolleyError;
 13 import com.android.volley.toolbox.ImageLoader;
 14 import com.android.volley.toolbox.Volley;
 15 import com.ghp.entity.Users;
 16 import com.ghp.tools.CustomRequest;
 17 import com.ghp.tools.GuodouRecipeApplication;
 18 import com.ghp.tools.ToRoundBitmap;
 19 import com.ghp.tools.UploadUtil;
 20 import com.google.gson.Gson;
 21 
 22 import android.annotation.SuppressLint;
 23 import android.app.Activity;
 24 import android.app.AlertDialog;
 25 import android.content.DialogInterface;
 26 import android.content.Intent;
 27 import android.graphics.Bitmap;
 28 import android.graphics.BitmapFactory;
 29 import android.graphics.drawable.BitmapDrawable;
 30 import android.graphics.drawable.Drawable;
 31 import android.net.Uri;
 32 import android.os.Bundle;
 33 import android.os.Environment;
 34 import android.os.Handler;
 35 import android.os.Message;
 36 import android.os.StrictMode;
 37 import android.provider.MediaStore;
 38 import android.view.Menu;
 39 import android.view.MenuItem;
 40 import android.view.View;
 41 import android.view.View.OnClickListener;
 42 import android.view.Window;
 43 import android.widget.EditText;
 44 import android.widget.ImageView;
 45 import android.widget.TextView;
 46 import android.widget.Toast;
 47 
 48 public class PersonnalMessageActivity extends Activity implements OnClickListener {
 49     private String userName;
 50     private String selecteSex;
 51     /**头像*/
 52     ImageView header_portrait_personnal_img;
 53     /**头像Bitmap*/
 54     private Bitmap headerPortait;
 55     private static String path="/sdcard/guodouRecipe/myHeader/";//sd路径
 56     private String[] items = new String[] { "选择本地图片", "拍照" };
 57     private String picPath = null;
 58     private RequestQueue requestQueue=null;
 59     private ImageLoader mImageLoader;
 60     
 61     TextView user_name_personnal_text;
 62     TextView user_tag_personnal_text;
 63     TextView user_sex_personnal_text;
 64     TextView user_area_personnal_text;
 65     
 66     ImageView go_back_fisrt;
 67     @SuppressLint("NewApi")
 68     @Override
 69     protected void onCreate(Bundle savedInstanceState) {
 70         this.requestWindowFeature(Window.FEATURE_NO_TITLE);
 71         super.onCreate(savedInstanceState);
 72         setContentView(R.layout.activity_personnal_message);
 73         Intent intent=getIntent();
 74         userName=intent.getStringExtra("userName");
 75         
 76         //*****头像的处理*****
 77         requestQueue=Volley.newRequestQueue(PersonnalMessageActivity.this);
 78         StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
 79         StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
 80         
 81         initView();
 82         //**********
 83         
 84         
 85         
 86         String url="http://172.27.211.1/guodouRecipe/servlet/find_user_message_servlet";
 87         CustomRequest request=new CustomRequest(Method.POST, url, new Listener<String>() {
 88 
 89             @Override
 90             public void onResponse(String result) {
 91                 // TODO Auto-generated method stub
 92                 Gson gson=new Gson();
 93                 Users u=gson.fromJson(result, Users.class);
 94                 user_name_personnal_text.setHint(userName);
 95                 user_tag_personnal_text.setText(u.getUserPersonnalTag());
 96                 user_sex_personnal_text.setText(u.getUserSex());
 97             }
 98         }, new ErrorListener(){
 99 
100             @Override
101             public void onErrorResponse(VolleyError arg0) {
102                 // TODO Auto-generated method stub
103                 
104             }
105             
106         });
107         request.setParam("userName", userName);
108         
109         GuodouRecipeApplication app=(GuodouRecipeApplication)PersonnalMessageActivity.this.getApplication();
110         app.getmRequestQueue().add(request);
111     }
112     
113     private void initView() {
114         header_portrait_personnal_img=(ImageView) findViewById(R.id.header_portrait_personnal_img);
115         header_portrait_personnal_img.setOnClickListener(listener);
116         
117         //*******头像处理*******
118         Bitmap bt = BitmapFactory.decodeFile(path + "/"+userName+"_header.jpg");//从Sd中找头像,转换成Bitmap
119         if(bt!=null){
120             @SuppressWarnings("deprecation")
121             Drawable drawable = new BitmapDrawable(bt);//转换成drawable
122             //圆形
123             header_portrait_personnal_img.setImageBitmap(ToRoundBitmap.toRoundBitmap(bt));
124             //方形
125             //header_portrait_personnal_img.setImageDrawable(drawable);
126         }else{
127             /**
128              *  如果SD里面没有则需要从服务器取头像,取回来的头像再保存在SD中
129              * 
130              */
131             mImageLoader = getImageLoader();
132              String url="http://172.27.211.1/guodouRecipe/headerportaitimages/";
133              String userImg=userName+"_header.jpg";
134             mImageLoader.get(url+userImg, mImageLoader.getImageListener(header_portrait_personnal_img, 0, 0));
135             Bitmap bm=header_portrait_personnal_img.getDrawingCache();
136             header_portrait_personnal_img.setImageBitmap(ToRoundBitmap.toRoundBitmap(bm));
137         }          
138         //****************************
139         
140         user_name_personnal_text=(TextView) findViewById(R.id.user_name_personnal_text);
141         //user_name_personnal_text.setOnClickListener(this);
142         user_tag_personnal_text=(TextView) findViewById(R.id.user_tag_personnal_text);
143         user_tag_personnal_text.setOnClickListener(this);
144         user_sex_personnal_text=(TextView) findViewById(R.id.user_sex_personnal_text);
145         user_sex_personnal_text.setOnClickListener(this);
146         user_area_personnal_text=(TextView) findViewById(R.id.user_area_personnal_text);
147         user_area_personnal_text.setOnClickListener(this);
148         
149         go_back_fisrt=(ImageView) findViewById(R.id.go_back_fisrt);
150         go_back_fisrt.setOnClickListener(this);
151     }
152     
153     //*******头像处理*******
154      private View.OnClickListener listener = new View.OnClickListener(){
155 
156         @Override
157         public void onClick(View v) {
158             // TODO Auto-generated method stub
159             showDialog();
160         }};
161          /**
162          * 显示选择对话框
163          */
164         private void showDialog() {
165             
166             new AlertDialog.Builder(this)
167             .setTitle("设置头像")
168             .setItems(items, new DialogInterface.OnClickListener() {
169 
170                 @Override
171                 public void onClick(DialogInterface dialog, int which) {
172                     switch (which) {
173                     case 0:
174                         Intent intent1 = new Intent(Intent.ACTION_PICK, null);
175                         intent1.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
176                         startActivityForResult(intent1, 11);
177                         break;
178                     case 1:
179                         
180                         Intent intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
181                         intent2.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
182                                 "/"+userName+"_header.jpg")));
183                         startActivityForResult(intent2, 22);//采用ForResult打开
184                         break;
185                     }
186                 }
187             })
188             .setNegativeButton("取消", new DialogInterface.OnClickListener() {
189 
190                 @Override
191                 public void onClick(DialogInterface dialog, int which) {
192                     dialog.dismiss();
193                 }
194             }).show();
195         }
196         
197         /**
198          * 调用系统的裁剪
199          * @param uri
200          */
201         public void cropPhoto(Uri uri) {
202             Intent intent = new Intent("com.android.camera.action.CROP");
203             intent.setDataAndType(uri, "image/*");
204             intent.putExtra("crop", "true");
205              // aspectX aspectY 是宽高的比例
206             intent.putExtra("aspectX", 1);
207             intent.putExtra("aspectY", 1);
208             // outputX outputY 是裁剪图片宽高
209             intent.putExtra("outputX", 150);
210             intent.putExtra("outputY", 150);
211             intent.putExtra("return-data", true);
212             startActivityForResult(intent, 33);
213         }
214         /**头像保存到sd*/
215         private void setPicToView(Bitmap mBitmap) {
216              String sdStatus = Environment.getExternalStorageState();  
217             if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用  
218                    return;  
219                }  
220             FileOutputStream b = null;
221             File file = new File(path);
222             file.mkdirs();// 创建文件夹
223             String fileName =path +userName+"_header.jpg";//图片名字
224             try {
225                 picPath = fileName;
226                 b = new FileOutputStream(fileName);
227                 mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把数据写入文件
228                  
229             } catch (FileNotFoundException e) {
230                 e.printStackTrace();
231             } finally {
232                 try {
233                     //关闭流
234                     b.flush();
235                     b.close();
236                 } catch (IOException e) {
237                     e.printStackTrace();
238                 }
239      
240             }
241         }
242     
243     @Override
244     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
245             switch (requestCode) {
246             case 11:
247                 if (resultCode == RESULT_OK) {
248                     cropPhoto(data.getData());//裁剪图片
249                 }
250      
251                 break;
252             case 22:
253                 if (resultCode == RESULT_OK) {
254                     File temp = new File(Environment.getExternalStorageDirectory()
255                             + "/"+userName+"_header.jpg");
256                     cropPhoto(Uri.fromFile(temp));//裁剪图片
257                 }
258      
259                 break;
260             case 33:
261                 if (data != null) {
262                     Bundle extras = data.getExtras();
263                     headerPortait = extras.getParcelable("data");
264                     if(headerPortait!=null){
265                         setPicToView(headerPortait);//保存在SD卡中
266                         File file = new File(picPath);
267                         String request = UploadUtil.uploadFile( file, "http://172.27.211.1/guodouRecipe/servlet/headerPortaitUploadServlet");                 
268                         if (request!=null&&!request.equals("")) {
269                             Toast.makeText(getApplicationContext(), "头像修改成功", 0).show();                        
270                         }
271                         header_portrait_personnal_img.setImageBitmap(ToRoundBitmap.toRoundBitmap(headerPortait));//用ImageView显示出来
272                     }
273                 }
274                 break;
275             default:
276                 break;
277      
278             }
279             super.onActivityResult(requestCode, resultCode, data);
280         };
281      //**********************************
282         @Override
283         public void onClick(View v) {
284             // TODO Auto-generated method stub
285             switch (v.getId()) {
286             case R.id.user_tag_personnal_text:
287                 //个性标签处理
288                 final EditText et=new EditText(PersonnalMessageActivity.this);
289                 new AlertDialog.Builder(PersonnalMessageActivity.this)
290                 .setTitle("编辑个性标签")
291                 .setView(et)
292                 .setPositiveButton("确定", 
293                         new DialogInterface.OnClickListener() {
294                     
295                     @Override
296                     public void onClick(DialogInterface dialog, int which) {
297                         final String changeUserPersonnalTag=et.getText().toString();
298                         //if (changeUserPersonnalTag!=null&&!changeUserPersonnalTag.equals("")) {
299                             String url="http://172.27.211.1/guodouRecipe/servlet/changeUserPersonnalTagServlet";
300                             CustomRequest postRequest=new CustomRequest(Method.POST, url, new Listener<String>() {
301 
302                                 @Override
303                                 public void onResponse(String ret) {
304                                         if(ret.equals("true")){
305                                             if(changeUserPersonnalTag!=null&&!changeUserPersonnalTag.equals("")){
306                                                 user_tag_personnal_text.setText(et.getText().toString());    
307                                                 myHandler.sendEmptyMessage(0);
308                                             }else{
309                                                 user_tag_personnal_text.setHint("未填写");
310                                                 Toast.makeText(getApplicationContext(), "没有编辑", 0).show();
311                                             }                                                                                    
312                                         }
313                                                                                     
314                                 }
315                             }, new ErrorListener(){
316 
317                                 @Override
318                                 public void onErrorResponse(VolleyError arg0) {
319                                     // TODO Auto-generated method stub
320                                     myHandler.sendEmptyMessage(1);
321                                 }});                
322                             postRequest.setParam("userName", userName);
323                             postRequest.setParam("changeUserPersonnalTag", changeUserPersonnalTag);
324                             requestQueue.add(postRequest);
325                                                             
326                         //} else {
327                         //    Toast.makeText(getApplicationContext(), "没有编辑", 0).show();
328                         //}
329                     }
330                 })
331                 .setNegativeButton("取消",new DialogInterface.OnClickListener() {
332             
333                     @Override
334                     public void onClick(DialogInterface arg0, int arg1) {
335                         Toast.makeText(getApplicationContext(), "已放弃编辑", 0).show();
336                     }
337                 })
338                 .setCancelable(false)
339                 .show();
340              
341                 break;
342             case R.id.user_sex_personnal_text:
343                 final String[] sexs={"",""};
344                 selecteSex=sexs[0];
345                 new AlertDialog.Builder(PersonnalMessageActivity.this)
346                 .setTitle("请选择性别")
347                 .setSingleChoiceItems(sexs, 0,
348                         new DialogInterface.OnClickListener() {
349                             
350                             @Override
351                             public void onClick(DialogInterface dialog, int which) {
352                                 // TODO Auto-generated method stub
353                                 selecteSex=sexs[which];
354                             }
355                         })
356                 .setPositiveButton("确定", 
357                         new DialogInterface.OnClickListener() {
358                             
359                             @Override
360                             public void onClick(DialogInterface dialog, int which) {
361                                 // TODO Auto-generated method stub
362                                 Toast.makeText(PersonnalMessageActivity.this, selecteSex, Toast.LENGTH_SHORT).show();
363                                 String url="http://172.27.211.1/guodouRecipe/servlet/changeUserSexServlet";
364                                 CustomRequest postRequest=new CustomRequest(Method.POST, url, new Listener<String>() {
365 
366                                     @Override
367                                     public void onResponse(String ret) {
368                                             if(ret.equals("true")){
369                                                 user_sex_personnal_text.setText(selecteSex);    
370                                                 //myHandler.sendEmptyMessage(0);
371                                                 
372                                             }                                                                                        
373                                     }
374                                 }, new ErrorListener(){
375 
376                                     @Override
377                                     public void onErrorResponse(VolleyError arg0) {
378                                         // TODO Auto-generated method stub
379                                         myHandler.sendEmptyMessage(1);
380                                     }});                
381                                 postRequest.setParam("userName", userName);
382                                 postRequest.setParam("selecteSex", selecteSex);
383                                 requestQueue.add(postRequest);
384                             }
385                         })
386                 .setNegativeButton("取消", null)
387                 .show();
388                 break;
389             case R.id.go_back_fisrt:
390                 Intent intent=new Intent(PersonnalMessageActivity.this,PersonalGuodouActivity.class);    
391                 intent.putExtra("userName", userName);
392                 setResult(5,intent);
393                 finish();
394                 overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
395                 
396                 break;
397             case R.id.user_area_personnal_text:
398                 Toast.makeText(getApplicationContext(), "还没有开放本功能", Toast.LENGTH_SHORT).show();
399                 break;
400             default:
401                 break;
402             }
403         } 
404         Handler myHandler=new Handler(){
405 
406             @Override
407             public void handleMessage(Message msg) {
408                 super.handleMessage(msg);
409                 switch (msg.what) {
410                 case 0:
411                     Toast.makeText(getApplicationContext(), "编辑成功", 0).show();
412                     break;
413                 case 1:
414                     Toast.makeText(getApplicationContext(), "请求失败了", 0).show();
415                     break;
416                 default:
417                     break;
418                 }
419             }
420             
421         };
422         public ImageLoader getImageLoader(){
423             GuodouRecipeApplication tna=(GuodouRecipeApplication) getApplication();
424             return tna.getmImageLoader();
425         }
426 }

activity的布局文件:

  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     tools:context="${relativePackage}.${activityClass}" >
  6 
  7     <RelativeLayout
  8         android:id="@+id/personal_message_header"
  9         android:layout_width="match_parent"
 10         android:layout_height="50dp"
 11         android:background="#efe7d7" >
 12 
 13         <ImageView
 14             android:id="@+id/go_back_fisrt"
 15             android:layout_width="wrap_content"
 16             android:layout_height="fill_parent"
 17             android:layout_alignParentLeft="true"
 18             android:adjustViewBounds="true"
 19             android:gravity="center_vertical"
 20             android:src="@drawable/goback_activity" />
 21 
 22         <ImageView
 23             android:id="@+id/header_logo"
 24             android:layout_width="wrap_content"
 25             android:layout_height="fill_parent"
 26             android:layout_gravity="center_vertical"
 27             android:layout_marginRight="5dp"
 28             android:layout_toRightOf="@+id/go_back_fisrt"
 29             android:adjustViewBounds="true"
 30             android:src="@drawable/ic_main_logo" />
 31 
 32         <TextView
 33             android:id="@+id/personal_user_name"
 34             android:layout_width="wrap_content"
 35             android:layout_height="fill_parent"
 36             android:layout_toRightOf="@+id/header_logo"
 37             android:gravity="center_vertical"
 38             android:textSize="18sp"
 39             android:textStyle="bold"
 40             android:text="个人资料" />
 41 
 42     </RelativeLayout>
 43     <RelativeLayout 
 44         android:id="@+id/personal_message_canter"
 45         android:layout_width="match_parent"
 46         android:layout_height="wrap_content"
 47         android:layout_below="@+id/personal_message_header"
 48         android:layout_marginLeft="15dp"
 49         android:layout_marginRight="15dp"
 50         android:layout_marginTop="10dp"
 51         android:layout_marginBottom="5dp">
 52     <TextView
 53         android:id="@+id/header_portrait_personnal"
 54         android:layout_width="120dp"
 55         android:layout_height="30dp"
 56         android:textSize="16sp"
 57         android:layout_marginTop="8dp"
 58         android:layout_marginBottom="8dp"
 59         android:gravity="center_vertical"
 60         android:text="头像" />
 61     <ImageView 
 62         android:id="@+id/header_portrait_personnal_img"
 63         android:layout_width="30dp"
 64         android:layout_height="30dp"
 65         android:layout_marginTop="8dp"
 66         android:layout_toRightOf="@+id/header_portrait_personnal"
 67         android:background="@drawable/default_user_photo"/>
 68     <ImageView 
 69         android:id="@+id/line1"
 70         android:layout_below="@+id/header_portrait_personnal"
 71         style="@style/left_drawer_item_line" />
 72     <TextView
 73         android:id="@+id/user_name_personnal"
 74         android:layout_width="120dp"
 75         android:layout_height="30dp"
 76         android:layout_below="@+id/line1"
 77         android:textSize="16sp"
 78         android:layout_marginTop="8dp"
 79         android:layout_marginBottom="8dp"
 80         android:gravity="center_vertical"
 81         android:text="昵称" />
 82     <TextView 
 83         android:id="@+id/user_name_personnal_text"
 84         android:layout_width="wrap_content"
 85         android:layout_height="30dp"
 86         android:layout_below="@+id/line1"
 87         android:layout_marginTop="8dp"
 88         android:layout_toRightOf="@+id/header_portrait_personnal"
 89         android:textSize="16sp"
 90         android:gravity="center_vertical"
 91         android:hint="昵称"/>
 92     <ImageView 
 93         android:id="@+id/line2"
 94         android:layout_below="@+id/user_name_personnal"
 95         style="@style/left_drawer_item_line" />
 96     
 97     <TextView
 98         android:id="@+id/user_tag_personnal"
 99         android:layout_width="120dp"
100         android:layout_height="30dp"
101         android:layout_below="@+id/line2"
102         android:textSize="16sp"
103         android:layout_marginTop="8dp"
104         android:layout_marginBottom="8dp"
105         android:gravity="center_vertical"
106         android:text="个性化标签" />
107     <TextView 
108         android:id="@+id/user_tag_personnal_text"
109         android:layout_width="wrap_content"
110         android:layout_height="30dp"
111         android:layout_below="@+id/line2"
112         android:layout_marginTop="8dp"
113         android:layout_toRightOf="@+id/user_tag_personnal"
114         android:textSize="16sp"
115         android:gravity="center_vertical"
116         android:hint="未填写"/>
117     <ImageView 
118         android:id="@+id/line3"
119         android:layout_below="@+id/user_tag_personnal"
120         style="@style/left_drawer_item_line" />
121     
122     <TextView
123         android:id="@+id/user_sex_personnal"
124         android:layout_width="120dp"
125         android:layout_height="30dp"
126         android:layout_below="@+id/line3"
127         android:textSize="16sp"
128         android:layout_marginTop="8dp"
129         android:layout_marginBottom="8dp"
130         android:gravity="center_vertical"
131         android:text="性别" />
132     <TextView 
133         android:id="@+id/user_sex_personnal_text"
134         android:layout_width="wrap_content"
135         android:layout_height="30dp"
136         android:layout_below="@+id/line3"
137         android:layout_marginTop="8dp"
138         android:layout_toRightOf="@+id/user_sex_personnal"
139         android:textSize="16sp"
140         android:gravity="center_vertical"
141         android:hint="未选择"/>
142     <ImageView 
143         android:id="@+id/line4"
144         android:layout_below="@+id/user_sex_personnal"
145         style="@style/left_drawer_item_line" />
146     
147     <TextView
148         android:id="@+id/user_area_personnal"
149         android:layout_width="120dp"
150         android:layout_height="30dp"
151         android:layout_below="@+id/line4"
152         android:textSize="16sp"
153         android:layout_marginTop="8dp"
154         android:layout_marginBottom="8dp"
155         android:gravity="center_vertical"
156         android:text="地区" />
157     <TextView 
158         android:id="@+id/user_area_personnal_text"
159         android:layout_width="wrap_content"
160         android:layout_height="30dp"
161         android:layout_below="@+id/line4"
162         android:layout_marginTop="8dp"
163         android:layout_toRightOf="@+id/user_area_personnal"
164         android:textSize="16sp"
165         android:gravity="center_vertical"
166         android:hint="请选择所在地区"/>
167     <ImageView 
168         android:id="@+id/line5"
169         android:layout_below="@+id/user_area_personnal"
170         style="@style/left_drawer_item_line" />
171     </RelativeLayout>
172 </RelativeLayout>

完整代码供大家参考,希望有用,中间有用到方形图片转换成圆形,方法在我的另一篇博文里

头像图片上传到sd及服务器

标签:des   android   style   blog   http   color   io   os   ar   

原文地址:http://www.cnblogs.com/jiuqing/p/4018758.html

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