无法获取图像URL并在Firebase数据库中显示

时间:2018-10-10 05:55:40

标签: java android firebase android-layout firebase-storage

Java文件

package com.example.edward.eventmanagementsystem.ManageEvent;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.edward.eventmanagementsystem.R;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import java.util.Calendar;


public class CreateEvent extends Activity {

    private static final String TAG = "activity_create_event";
    private Uri filePath;
    private TextView mDisplayDate;
    private DatePickerDialog.OnDateSetListener mDateSetListener;
    private DatabaseReference mDatabaseReference;
    Button mRegisterButton;
    EditText mEventNameText, mContactNumText, mEventLocationText;
    TextView mEventDate;
    RadioGroup mEventType;
    FirebaseStorage storage;
    StorageReference storageRef,imageRef;
    private static final int Selected = 100;
    ProgressDialog progressDialog;
    UploadTask uploadTask;
    Uri uriImage;
    String urlIMAGE="";

    public static final int  RESULT_LOAD_IMAGE = 1;
    ImageView imageToUpload;

//    @Override
//    public void onClick(View v) {
//        switch (v.getId()){
//            case R.id.imageToUpload:
//                Intent galleyIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//                startActivityForResult(galleyIntent, RESULT_LOAD_IMAGE);
//                break;
//        }
//    }
//
//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null){
//            Uri selectedImage = data.getData();
//            imageToUpload.setImageURI(selectedImage);
//        }
//    }




    /*    private DatabaseReference mDatabase;*/
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        FirebaseDatabase firebaseDatabase;
        mDatabaseReference = FirebaseDatabase.getInstance().getReference();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_event);

        mRegisterButton = (Button)findViewById(R.id.btnRegisterEvent);

        storage = FirebaseStorage.getInstance();
        storageRef = storage.getReference();

        mDisplayDate = (TextView) findViewById(R.id.RegisterEventStartDate);
        //mDisplayDate = (TextView) findViewById(R.id.RegisterEventEndDate);
        mDisplayDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Calendar cal = Calendar.getInstance();
                    int year = cal.get(Calendar.YEAR);
                    int month = cal.get(Calendar.MONTH);
                    int day = cal.get(Calendar.DAY_OF_MONTH);

                    DatePickerDialog dialog = new DatePickerDialog(
                            CreateEvent.this,
                            android.R.style.Theme_Holo_Light_Dialog_MinWidth,
                            mDateSetListener,
                            year, month, day);
                    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    dialog.show();
                }
        });

        mDateSetListener = new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int month, int day) {
                month = month + 1;
                Log.d(TAG, "onDateSet: date: mm/dd/yyyy: " + month + "/" + day + "/" + year);

                String date = month +  "/"  + day + "/" + year;
                mDisplayDate.setText(date);
            }
        };

        //perform action upload image
        imageToUpload = (ImageView) findViewById(R.id.imageToUpload);
        imageToUpload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ChooseImage();
            }
        });



        //insert data to database
        mEventNameText = (EditText) findViewById(R.id.RegisterEventName);
        mContactNumText = (EditText) findViewById(R.id.RegisterContactNumber);
        mEventDate = (TextView) findViewById(R.id.RegisterEventStartDate);
        mEventType =  (RadioGroup) findViewById(R.id.RegisterEventRadiogroup);
        mEventLocationText = (EditText) findViewById(R.id.RegisterEventLocation);

//        mDatabase = FirebaseDatabase.getInstance(),getReferrer();
//
//        mRegisterButton.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                String name = mEventNameText.getText().toString();
//            }
//        });

        mRegisterButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UploadFoto();
                Toast.makeText(CreateEvent.this,"Information created succesfully!", Toast.LENGTH_SHORT).show();
                finish();
            }
        });

    }

    //new
    public void ChooseImage() {
        Toast.makeText(CreateEvent.this,"Choose Image",Toast.LENGTH_SHORT).show();
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, Selected);
//        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//        galleyIntent.setType("image/*");
//        startActivityForResult(photoPickerIntent, RESULT_LOAD_IMAGE);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
        switch (requestCode) {
            case Selected:
                if (resultCode == RESULT_OK) {
                    uriImage = imageReturnedIntent.getData();
                    imageToUpload.setImageURI(uriImage);
                }
        }
    }


    public void UploadFoto() {

        imageRef = storageRef.child(mEventNameText.getText().toString());

        progressDialog = new ProgressDialog(this);
        progressDialog.setMax(100);
        progressDialog.setMessage("Uploading...");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.show();
        progressDialog.setCancelable(false);

        uploadTask = imageRef.putFile(uriImage);

        uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
                progressDialog.incrementProgressBy((int) progress);
            }
        });

        uploadTask.addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception exception) {
                Toast.makeText(getApplicationContext(),"Failed!",Toast.LENGTH_SHORT).show();
                progressDialog.dismiss();
            }
        }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//                Uri downloadUrl = taskSnapshot.getUploadSessionUri();
//                Uri downloadUrl = taskSnapshot.getDownloadUrl();//
//                Uri downloadUrl = storageRef.getDownloadUrl();


                urlIMAGE = downloadUrl.toString();
                progressDialog.dismiss();
            }
        });
        int selectedId = mEventType.getCheckedRadioButtonId();
        RadioButton radioButton = (RadioButton)findViewById(selectedId);
        EventInfo eventInfo =  new EventInfo(urlIMAGE, mEventNameText.getText().toString(), mContactNumText.getText().toString(),
                mEventDate.getText().toString(), radioButton.getText().toString(),mEventLocationText.getText().toString());

        mDatabaseReference.child("ListEventInformation").push().setValue(eventInfo);
//        progressDialog.dismiss();
    }

}

xml文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ManageEvent.CreateEvent">


    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Alright! Let's create your new event"
            android:layout_marginTop="40dp"
            android:layout_centerHorizontal="true"
            android:textSize="20dp"
            android:textStyle="bold"
            android:textColor="@color/black"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageToUpload"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="10dp"
            android:background="@color/light_blue"
            android:src="@drawable/ic_person_black_24dp" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/RegisterEventName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:hint="@string/event_name"
                android:inputType="text"
                android:textColor="#000000"
                android:textColorHint="@android:color/darker_gray"
                android:textColorLink="@android:color/holo_red_dark" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/RegisterContactNumber"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:hint="@string/contact_number"
                android:inputType="phone"
                android:textColor="@color/black"
                android:textColorHint="@color/darkGrey"
                android:textColorLink="@android:color/holo_red_dark" />/>
        </android.support.design.widget.TextInputLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Event Date: "
                android:textSize="18dp"
                android:textColor="@color/black"
                android:layout_marginLeft="15dp"/>

            <TextView
                android:id="@+id/RegisterEventStartDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:hint="Select Date"
                android:textSize="18dp"/>
        </LinearLayout>

<!--        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Event End Date  : "
                android:textSize="18dp"
                android:layout_marginTop="10dp"
                android:textColor="@color/black"
                android:layout_marginLeft="15dp"/>

            <TextView
                android:id="@+id/RegisterEventEndDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="10dp"
                android:hint="Select Date"
                android:textSize="18dp"/>
        </LinearLayout>-->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="6dp"
            android:gravity="center_vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:textColor="@color/black"
                android:text="@string/label_type_of_event"
                android:textSize="18dp" />

            <RadioGroup
                android:id="@+id/RegisterEventRadiogroup"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/type1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/type_of_event1"
                    android:textSize="18dp" />

                <RadioButton
                    android:id="@+id/type2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/type_of_event2"
                    android:textSize="18dp" />

            </RadioGroup>
        </LinearLayout>>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/RegisterEventLocation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:hint="@string/event_location"
                android:inputType="text"
                android:textColor="@color/black"
                android:textColorHint="@color/darkGrey"
                android:textColorLink="@android:color/holo_red_dark" />
        </android.support.design.widget.TextInputLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="horizontal">

            <Button
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="10dp"
                android:text="Confirm"
                android:id="@+id/btnRegisterEvent"/>

        </LinearLayout>
    </LinearLayout>

</RelativeLayout>
</ScrollView>

我在这方面有问题。。。我猜

public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
    #1//Uri downloadUrl = taskSnapshot.getUploadSessionUri();  
    #2//Uri downloadUrl = taskSnapshot.getDownloadUrl();//
    #3//Uri downloadUrl = storageRef.getDownloadUrl();


      urlIMAGE = downloadUrl.toString();
      progressDialog.dismiss();
}

当我运行#1 时,所有可以上传到Firebase的信息都包括将照片保存到Firebase存储中,但是无法从Firebase存储中显示数据库中照片的URL

当我运行#2 时,getDownloadUrl();出现了问题,类型不兼容

3是我从互联网上看到的样本,但也没有。

1 个答案:

答案 0 :(得分:0)

enter image description here这一切正常, 首先将尝试并了解如何使Firebase工作。非常容易享受。

MainActivity.java

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

import static android.widget.Toast.LENGTH_SHORT;



public class MainActivity extends AppCompatActivity {

    private EditText inputEmail, inputPassword,f_name,l_name,phone;
    private Button  btnSignUp,back;
    private ProgressBar progressBar;
    private FirebaseAuth auth;

    FirebaseStorage storage;

    private DatabaseReference mCustomerDatabase,mCustomerDatabase1;

    ImageView profileImage;
    Uri resultUri  = Uri.parse("android.resource://com.example.chetan.printerprinting/" + R.drawable.ic_launcher_background);
    ProgressDialog progress;
    public static final int PICK_IMAGE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        mCustomerDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child("Customers").child("UploadFile");

        storage = FirebaseStorage.getInstance();



            btnSignUp = (Button) findViewById(R.id.sign_up_button);
            inputEmail = (EditText) findViewById(R.id.email);
            inputPassword = (EditText) findViewById(R.id.password);
            f_name = (EditText) findViewById(R.id.f_name);
            l_name = (EditText) findViewById(R.id.l_name);
            phone = (EditText) findViewById(R.id.phone);
            back = (Button) findViewById(R.id.back);
            profileImage = (ImageView) findViewById(R.id.image_profile);





            profileImage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){
                        selectPdf();
                    }
                    else {
                        ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},9);
                    }
                }
            });

            btnSignUp.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    final String email = inputEmail.getText().toString().trim();
                    final String password = inputPassword.getText().toString().trim();
                    final String F_name = f_name.getText().toString().trim();
                    final String L_name = l_name.getText().toString().trim();
                    final String Phone = phone.getText().toString().trim();



                    if (TextUtils.isEmpty(F_name)) {
                        f_name.setError("Enter First Name!");
                        return;
                    }


                    if (TextUtils.isEmpty(L_name)) {
                        l_name.setError("Enter Last Name!");
                        return;
                    }


                    if (TextUtils.isEmpty(Phone)) {
                        phone.setError("Enter Phone Number!");
                        return;
                    }
                    if(isValidPhone(Phone)){

                        //Toast.makeText(getApplicationContext(),"Phone number is valid",Toast.LENGTH_SHORT).show();
                    }else {
                        phone.setError("Phone number is not valid");
                        // Toast.makeText(getApplicationContext(),"Phone number is not valid",Toast.LENGTH_SHORT).show();
                        return;
                    }

                    if (TextUtils.isEmpty(email)) {
                        inputEmail.setError("Enter Email Address!");
                        return;
                    }
                    else if (isValidEmail(email)){

                    }
                    else {
                        inputEmail.setError("Enter Valid Email Address!");
                        return;
                    }

                    if (TextUtils.isEmpty(password)) {
                        inputPassword.setError("Enter Password!");
                        return;
                    }

                    if (password.length() < 6) {
                        inputPassword.setError("Password too short, enter minimum 6 characters!");
                        return;
                    }



                                        Map userInfo = new HashMap();
                                        userInfo.put("email", email);
                                        userInfo.put("password", password);
                                        userInfo.put("f_name", F_name);
                                        userInfo.put("l_name", L_name);
                                        userInfo.put("phone", Phone);

                                        mCustomerDatabase.updateChildren(userInfo);
                                        final String fileName = System.currentTimeMillis()+"";

                                        if(resultUri != null) {
                                            StorageReference storageReference = storage.getReference();
                                            storageReference.child("profileImageUrl").child(fileName).putFile(resultUri)
                                                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                                                        @Override
                                                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                                                            String url = taskSnapshot.getDownloadUrl().toString();
                                                            mCustomerDatabase.child("profileImageUrl").setValue(url).addOnCompleteListener(new OnCompleteListener<Void>() {
                                                                @Override
                                                                public void onComplete(@NonNull Task<Void> task) {


                                                                    if (task.isSuccessful()){ }
                                                                    else{

                                                                        Toast.makeText(getApplicationContext(),"File not Successfully Uploaded",LENGTH_SHORT).show(); }
                                                                }
                                                            });
                                                        }
                                                    }).addOnFailureListener(new OnFailureListener() {
                                                @Override
                                                public void onFailure(@NonNull Exception e) {

                                                    Toast.makeText(getApplicationContext(),"File not Successfully Uploaded",LENGTH_SHORT).show();

                                                }
                                            }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
                                                @Override
                                                public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {

                                                }
                                            });
                                        }else{


                                        }

                                    }



            });

            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });

        }



    public boolean isValidPhone(CharSequence phone) {
        boolean check=false;
        if(!Pattern.matches("[a-zA-Z]+", phone))
        {
            if(phone.length() < 10 || phone.length() > 11)
            {
                check = false;
            }
            else
            {
                check = true;
            }
        }
        else
        {
            check=false;
        }
        return check;
    }


    public static boolean isValidEmail(CharSequence target) {
        return (!TextUtils.isEmpty(target) && Patterns.EMAIL_ADDRESS.matcher(target).matches());
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (requestCode == 9 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
            selectPdf();
        }
        else{
            Toast.makeText(getApplicationContext(),"Please provide the permission", LENGTH_SHORT).show();

        }
    }


    private void selectPdf() {

        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        startActivityForResult(intent,86);
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == 86 && resultCode == RESULT_OK && data != null){

            final Uri imageUri = data.getData();
            resultUri = imageUri;
            profileImage.setImageURI(resultUri);
        }
        else {
            Toast.makeText(getApplicationContext(),"Please select file", LENGTH_SHORT).show();
        }
    }






}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FBFBFB"
    android:orientation="vertical"
    tools:context=".MainActivity"
    tools:layout_editor_absoluteY="25dp">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="30dp"
                android:textColor="#4B74FF"
                android:layout_marginRight="30dp"
                android:layout_marginLeft="30dp"
                android:text="Create an account"/>



            <ImageView
                android:id="@+id/image_profile"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:layout_marginRight="50dp"
                android:layout_marginLeft="50dp"
                android:layout_below="@id/text"
                android:layout_marginTop="20dp"
                android:src="@drawable/ic_launcher_background" />


            <EditText
                android:id="@+id/f_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="First Name"
                android:layout_marginTop="20dp"
                android:layout_marginRight="30dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/image_profile"
                android:inputType="textEmailAddress"
                android:textColor="#aaa"
                android:fontFamily="monospace"
                android:textSize="22dp" />
            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_marginTop="-10dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/f_name"
                android:layout_marginRight="30dp"
                android:background="#aaaaaa" />

            <EditText
                android:id="@+id/l_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Last Name"
                android:layout_marginTop="20dp"
                android:layout_marginRight="30dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/f_name"
                android:inputType="textEmailAddress"
                android:textColor="#aaa"
                android:fontFamily="monospace"
                android:textSize="22dp" />

            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_marginTop="-10dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/l_name"
                android:layout_marginRight="30dp"
                android:background="#aaaaaa" />

            <EditText
                android:id="@+id/phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Phone No."
                android:layout_marginTop="20dp"
                android:layout_marginRight="30dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/l_name"
                android:inputType="phone"
                android:textColor="#aaa"
                android:fontFamily="monospace"
                android:textSize="22dp" />
            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_marginTop="-10dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/phone"
                android:layout_marginRight="30dp"
                android:background="#aaaaaa" />


            <EditText
                android:id="@+id/email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="email"
                android:layout_marginRight="30dp"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/phone"
                android:inputType="textEmailAddress"
                android:textColor="#aaa"
                android:fontFamily="monospace"
                android:textSize="22dp" />
            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_marginTop="-10dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/email"
                android:layout_marginRight="30dp"
                android:background="#aaaaaa" />


            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="password"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:layout_marginTop="20dp"
                android:layout_below="@id/email"
                android:maxLength="11"
                android:inputType="textPassword"
                android:textColor="#aaa"
                android:textSize="22dp"
                />
            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:layout_marginTop="-10dp"
                android:layout_marginLeft="30dp"
                android:layout_below="@id/password"
                android:layout_marginRight="30dp"
                android:background="#aaaaaa" />


            <Button
                android:id="@+id/sign_up_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:textColor="@android:color/background_light"
                android:layout_marginTop="10dp"
                android:padding="20dp"
                android:layout_marginLeft="30dp"
                android:layout_marginRight="30dp"
                android:textSize="20dp"
                android:layout_marginBottom="10dp"
                android:layout_below="@id/password"
                android:textStyle="bold" />

        </RelativeLayout>

    </ScrollView>
    <!-- Link to Login Screen -->


</RelativeLayout>

希望完全使用