Android帶頭像的用戶註冊頁面

来源:http://www.cnblogs.com/shouce/archive/2016/06/02/5551796.html
-Advertisement-
Play Games

詳細的圖文可以到我的百度經驗去查看:http://jingyan.baidu.com/article/cd4c2979eda109756e6e60de.html 首先是註冊頁面的佈局: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2 ...


詳細的圖文可以到我的百度經驗去查看:http://jingyan.baidu.com/article/cd4c2979eda109756e6e60de.html

首先是註冊頁面的佈局:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 <?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="用戶名:" />                   <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="密碼:" />                   <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="確認密碼:" />                   <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地址:" />                   <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="選擇頭像" />       </LinearLayout>   </LinearLayout>

然後是圖庫的頁面佈局,由用戶去選擇圖片,這裡我就用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>
複製代碼

然後我們在註冊頁面的Activity寫入以下代碼:

複製代碼
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方法:
    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);
        }
    }
複製代碼

點擊按鈕跳轉到圖庫Activity頁面中。

在圖庫Activity裡面寫入以下代碼響應用戶點擊圖片並通過Intent傳遞給前一個Activity:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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();             }         });

結果如下:

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • getTIme()方法是把一個date對象轉成毫秒; parse方法是把一個時間格式的字元串轉換成毫秒; 1. date1=new Date("2002/1/1")date2=new Date("2002/1/2")alert(Date.parse(date1)<Date.parse(date2)) ...
  • 如果在AndroidManifest文件中將某個Content Provider的exported屬性設置為true,則多了一個攻擊該APP的攻擊點。如果此Content Provider的實現有問題,則可能產生任意數據訪問、SQL註入、目錄遍歷等風險。 ...
  • 升級SDK可用Background 多加了個按鈕,可用一邊寫代碼一邊下載SDK Instant Run 修改代碼一秒啟動 APK analyzer 分析任何的APK 查看APK下載包的大小,解壓後的實際大小 反編譯資源文件,甚至能還原layout中的資源id,還有,代碼,代碼,代碼,重要的事情說三遍 ...
  • 1 效果圖 2 xml文件 activity_pie_chart.xml 3 java文件 ...
  • Android中的控制項的使用方式和iOS中控制項的使用方式基本相同,都是事件驅動。給控制項添加事件也有介面回調和委托代理的方式。今天這篇博客就總結一下Android中常用的基本控制項以及佈局方式。說到佈局方式Android和iOS還是區別挺大的,在iOS中有Frame絕對佈局和AutoLayout相對佈局 ...
  • 1.效果圖 2.xml代碼 activity_column_chart.xml 3.java代碼 ...
  • 一,效果圖。 二,工程圖。 三,代碼。 RootViewController.h RootViewController.m ...
  • 做過的大大小小的 .NET Web 項目如下: (1)售樓系統產品 「Role: Team Member」 (2)中弘合同管理系統 「Role: Team Member」 (3)Gammon Portal 金門建築內部門戶 「Role: Team Leader」 (4)Hopewell Portal ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...