天天看點

android純代碼構造的頁面,Android純代碼布局LinearLayout

mProgressView=newProgressBar(this);

mProgressView.setLayoutParams(newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.WRAP_CONTENT,

LinearLayout.LayoutParams.WRAP_CONTENT));

mProgressView.setBackgroundColor(Color.WHITE);

mProgressView.setBottom(8);

mProgressView.setVisibility(View.GONE);

mLoginFormView=newScrollView(this);

mLoginFormView.setLayoutParams(newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.MATCH_PARENT));

//根布局參數

LinearLayout.LayoutParams layoutParamsRoot =newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT);

layoutParamsRoot.gravity= Gravity.CENTER;

//根布局

LinearLayout layoutRoot =newLinearLayout(this);

layoutRoot.setLayoutParams(layoutParamsRoot);

layoutRoot.setOrientation(LinearLayout.VERTICAL);

layoutRoot.addView(mProgressView);

//title布局

LinearLayout.LayoutParams layoutParamsTitle =newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT);

layoutParamsTitle.gravity=Gravity.CENTER_HORIZONTAL;

//title

AppCompatTextView title =newAppCompatTextView(this);

title.setText("登入");

title.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);

title.setTextSize(30);

layoutRoot.addView(title,layoutParamsTitle);

//使用者名text布局

LinearLayout.LayoutParams layoutParamsEmil =newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT);

layoutParamsEmil.gravity=Gravity.CENTER_HORIZONTAL;

//使用者名text

mEmailView=newAutoCompleteTextView(this);

mEmailView.setHint("Email");

mEmailView.setInputType(0);

mEmailView.setMaxLines(1);

//使用者名布局

TextInputLayout inputLayoutEmil =newTextInputLayout(this);

inputLayoutEmil.addView(mEmailView,layoutParamsEmil);

layoutRoot.addView(inputLayoutEmil,newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT));

//密碼Text布局

LinearLayout.LayoutParams layourParamsPassword =newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT);

layourParamsPassword.gravity=Gravity.CENTER_HORIZONTAL;

//密碼Text

mPasswordView=newEditText(this);

mPasswordView.setHint("Password");

mPasswordView.setImeActionLabel("Sign in",0);

mPasswordView.setImeOptions(0);

mPasswordView.setInputType(InputType.TYPE_CLASS_TEXT| InputType.TYPE_TEXT_VARIATION_PASSWORD);

mPasswordView.setMaxLines(1);

//密碼布局

TextInputLayout inputLayoutPassword =newTextInputLayout(this);

inputLayoutPassword.addView(mPasswordView,layourParamsPassword);

layoutRoot.addView(inputLayoutPassword,newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT));

//登入Button布局

LinearLayout.LayoutParams layoutParamsLoginButton =newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT);

layoutParamsLoginButton.topMargin=16;

layoutParamsLoginButton.gravity=Gravity.CENTER_HORIZONTAL;

//登入Button

Button buttonLogin =newButton(this);

buttonLogin.setText("登入");

buttonLogin.setOnClickListener(newOnClickListener() {

@Override

public voidonClick(View view) {

attemptLogin();

}

});

layoutRoot.addView(buttonLogin,layoutParamsLoginButton);

//注冊Button布局

LinearLayout.LayoutParams layoutParamsRegistButton =newLinearLayout.LayoutParams(

LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT);

layoutParamsLoginButton.topMargin=16;

layoutParamsRegistButton.gravity=Gravity.CENTER_HORIZONTAL;

//注冊Button

Button buttonRegist =newButton(this);

buttonRegist.setText("注冊");

buttonRegist.setOnClickListener(newOnClickListener() {

@Override

public voidonClick(View view) {

jumpRegist();

}

});

layoutRoot.addView(buttonRegist,layoutParamsRegistButton);

mLoginFormView.addView(layoutRoot);

setContentView(mLoginFormView);