Android development path-coding implementation software interface

Source: Internet
Author: User

Implement a login interface:

Relative layout:

Package CN. csdn. codeui; import android. app. activity; import android. OS. bundle; import android. view. viewgroup. layoutparams; import android. widget. button; import android. widget. edittext; import android. widget. relativelayout; import android. widget. textview; public class loginrelativeactivity extends activity {protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); initui ();} private void initui () {relativelayout rlayout = new relativelayout (this); int id = 100; /** Add a textview */textview textview1 = new textview (this);/** Android: Id = "" */textview1.setid (ID);/** Android: TEXT = "username:" */textview1.settext ("username:");/** Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" */relativelayout. layoutparams textparams1 = new relativelayout. layoutparams (layoutparams. wrap_content, layoutparams. wrap_content);/** Android: layout_alignparentleft = "true" */textparams1.addrule (relativelayout. align_parent_left); rlayout. addview (textview1, textparams1); // int id1 = 200; edittext useredit = new edittext (this); useredit. setid (id1); relativelayout. layoutparams editparams1 = new relativelayout. layoutparams (layoutparams. fill_parent, layoutparams. wrap_content);/** Android: layout_torightof = "id value" */editparams1.addrule (relativelayout. right_of, ID); rlayout. addview (useredit, editparams1); // int id = 300; textview textview2 = new textview (this); textview2.setid (ID ); textview2.settext ("Password:"); relativelayout. layoutparams textparams2 = new relativelayout. layoutparams (layoutparams. wrap_content, layoutparams. wrap_content); textparams2.addrule (relativelayout. below, id1); rlayout. addview (textview2, textparams2); // int id1 = 400; edittext passedit = new edittext (this); passedit. setid (id1); relativelayout. layoutparams editparams2 = new relativelayout. layoutparams (layoutparams. fill_parent, layoutparams. wrap_content); editparams2.addrule (relativelayout. below, id1); editparams2.addrule (relativelayout. right_of, ID); rlayout. addview (passedit, editparams2); // int Id2 = 500; button login = new button (this); login. setid (Id2); login. settext ("login"); relativelayout. layoutparams loginparams = new relativelayout. layoutparams (layoutparams. wrap_content, layoutparams. wrap_content); loginparams. addrule (relativelayout. below, id1); loginparams. addrule (relativelayout. align_parent_right); rlayout. addview (login, loginparams); // button insert = new button (this); insert. settext ("register"); relativelayout. layoutparams insertparams = new relativelayout. layoutparams (layoutparams. wrap_content, layoutparams. wrap_content); insertparams. addrule (relativelayout. below, id1); insertparams. addrule (relativelayout. left_of, Id2); rlayout. addview (insert, insertparams); setcontentview (rlayout );}}

 

:

 

Table layout:

Package CN. csdn. codeui; import android. app. activity; import android. OS. bundle; import android. view. viewgroup. layoutparams; import android. widget. button; import android. widget. edittext; import android. widget. tablelayout; import android. widget. tablerow; import android. widget. textview; public class logintableactivity extends activity {protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); initui ();} private void initui () {// table layout tablelayout tlayout = new tablelayout (this); tlayout. setcolumnstretchable (1, true); // row tablerow tablerow1 = new tablerow (this); textview textview1 = new textview (this); textview1.settext ("username :"); tablerow1.addview (textview1); edittext useredit = new edittext (this); tablerow1.addview (useredit); tlayout. addview (tablerow1); tablerow tablerow2 = new tablerow (this); textview textview2 = new textview (this); textview2.settext ("Password:"); tablerow2.addview (textview2 ); edittext passedit = new edittext (this); tablerow2.addview (passedit); tlayout. addview (tablerow2); tablerow tablerow3 = new tablerow (this); button btn0 = new button (this); btn0.settext ("login"); tablerow3.addview (btn0 ); button btn1 = new button (this); btn1.settext ("register"); tablerow3.addview (btn1); tlayout. addview (tablerow3); setcontentview (tlayout );}}

 

:

 

Linear layout:

Package cn. csdn. codeui; import android. app. activity; import android. OS. bundle; import android. view. viewGroup. layoutParams; import android. widget. button; import android. widget. editText; import android. widget. linearLayout; import android. widget. textView; public class LoginLinearActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); init ();} private void init () {// linear layout LinearLayout linearLayout = new LinearLayout (this);/** android: orientation = "vertical" */linearLayout. setOrientation (LinearLayout. VERTICAL); LayoutParams layoutParams = new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. FILL_PARENT); // TextView userText = new TextView (this); userText. setText ("username:"); LayoutParams userTextParams = new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT); linearLayout. addView (userText, userTextParams); /////// EditText userEdit = new EditText (this); LayoutParams userEditParams = new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT); linearLayout. addView (userEdit, userEditParams); // TextView passText = new TextView (this); passText. setText ("Password:"); LayoutParams passTextParams = new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT); linearLayout. addView (passText, passTextParams); ///// EditText passEdit = new EditText (this); LayoutParams passEditParams = new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT); linearLayout. addView (passEdit, passEditParams); // Button login = new Button (this); login. setText ("login"); LayoutParams loginParams = new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT); linearLayout. addView (login, loginParams); // Button insert = new Button (this); insert. setText ("register"); LayoutParams insertParams = new LayoutParams (LayoutParams. FILL_PARENT, LayoutParams. WRAP_CONTENT); linearLayout. addView (insert, insertParams); setContentView (linearLayout, layoutParams );}}

 

:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.