Android user registration page with Avatar, android User Registration
Detailed graphics can go to my Baidu experience to view: http://jingyan.baidu.com/article/cd4c2979eda109756e6e60de.html
First, the registration page layout:
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: paddingTop = "20px" android: orientation = "horizontal"> <LinearLayout android: id = "@ + id/linearLayout1" android: orientation = "vertical" android: layout_weight = "2" android: paddingLeft = "20px" android: layout_width = "wrap_content" android: layout_height = "wrap_content"> <TableLayout android: id = "@ + id/tableLayout1" android: layout_width = "match_parent" android: layout_height = "wrap_content"> <TableRow android: id = "@ + id/tableRow1" android: layout_width = "wrap_content" android: layout_height = "wrap_content"> <TextView android: id = "@ + id/textView1" android: textSize = "20px" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "username:"/> <EditText android: id = "@ + id/user" android: minWidth = "400px" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </TableRow> <TableRow android: id = "@ + id/tableRow2" android: layout_width = "wrap_content" android: layout_height = "wrap_content"> <TextView android: id = "@ + id/textView2" android: textSize = "20px" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Password:"/> <EditText android: id = "@ + id/pwd" android: inputType = "textPassword" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </TableRow> <TableRow android: id = "@ + id/tableRow3" android: layout_width = "wrap_content" android: layout_height = "wrap_content"> <TextView android: id = "@ + id/textView3" android: textSize = "20px" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Confirm Password:"/> <EditText android: id = "@ + id/repwd" android: inputType = "textPassword" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </TableRow> <TableRow android: id = "@ + id/tableRow4" android: layout_width = "wrap_content" android: layout_height = "wrap_content"> <TextView android: id = "@ + id/textView4" android: textSize = "20px" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "E-mail address:"/> <EditText android: id = "@ + id/email" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </TableRow> </TableLayout> </LinearLayout> <LinearLayout android: id = "@ + id/linearLayout2" android: orientation = "vertical" android: gravity = "center_horizontal" android: layout_width = "wrap_content" android: layout_weight = "1" android: layout_height = "wrap_content"> <ImageView android: id = "@ + id/imageView1" android: layout_width = "158px" android: layout_height = "150px" android: src = "@ drawable/ic_launcher"/> <Button android: id = "@ + id/button1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "select Avatar"/> </LinearLayout>
Then there is the page layout of the image library. Users can select images. Here I will use several photos in windows.
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <GridView android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/gridView" android:numColumns="4" /></LinearLayout>
Then, we write the following code in the Activity on the registration page:
Button button1 = (Button) findViewById (R. id. button1); button1.setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (MainActivity. this, HeadActivity. class); startActivityForResult (intent, 0x11) ;}}); @ Override onActivityResult method: protected void onActivityResult (int requestCode, int resultCode, Intent data) {super. onActivityResult (requestCode, resultCode, data); if (requestCode = 0x11 & requestCode = 0x11) {Bundle bundle = data. getExtras (); int imageId = bundle. getInt ("imageId"); ImageView imageView = (ImageView) findViewById (R. id. imageView1); imageView. setImageResource (imageId );}}
Click the button to go to the gallery Activity page.
Write the following code in the gallery Activity to respond to the user's clicking the image and pass it to the previous Activity through Intent:
GridView gridView=(GridView)findViewById(R.id.gridView); BaseAdapter adapter=new BaseAdapter() { @Override public int getCount() { return imageId.length; } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if(convertView==null){ imageView=new ImageView(HeadActivity.this); imageView.setAdjustViewBounds(true); imageView.setMaxHeight(58); imageView.setMaxWidth(50); imageView.setPadding(5,5,5,5); }else{ imageView=(ImageView)convertView; } imageView.setImageResource(imageId[position]); return imageView; } }; gridView.setAdapter(adapter); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent=getIntent(); Bundle bundle=new Bundle(); bundle.putInt("imageId",imageId[position]); intent.putExtras(bundle); setResult(0x11,intent); finish(); } });
The result is as follows: