. NET programmer play to Android Development---(4) Register page layout

Source: Internet
Author: User

in the previous article we introduced the landing page layout, this section we look at the layout of the registration page, in fact, the page layout is similar, to be familiar with the use of basic controls.

1. Add Registration page

Right-click on the Layout folder to add the registration page.


Click Done and the page is ready to be added. Add a control to the page with the following XML code

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "   ; <linearlayout android:layout_width= "fill_parent" android:layout_weight= "0.9" android:layout_height= "Fill_  Parent "> </LinearLayout> <linearlayout android:layout_width=" fill_parent "android:layout_weight=" 0.1 " android:orientation= "vertical" android:layout_height= "fill_parent" > <linearlayout android:layout_margi nleft= "10px" android:layout_marginright= "10px" android:gravity= "center" android:layout_width= "Fill_parent" and    roid:orientation= "Horizontal" android:layout_height= "wrap_content" > <textview android:textsize= "8pt" android:text= "User name" android:layout_weight= "0.75" android:layout_width= "fill_parent" android:layout_height= "Wrap_ Content "> </textview> <edittext android:layout_weight= "0.25" android:layout_width= "Fill_parent" android:t ext= "Please enter user name" android:layout_height= "Wrap_content" > </EditText> </linearlayou t> <linearlayout android:layout_marginleft= "10px" android:layout_marginright= "10px" android:gravity= "center" Android:layout_width= "fill_parent" android:orientation= "horizontal" android:layout_height= "Wrap_content" > < TextView android:textsize= "8pt" android:text= "password" android:layout_weight= "0.75" android:layou              T_width= "Fill_parent" android:layout_height= "wrap_content" > </TextView> <edittext android:layout_weight= "0.25" android:layout_width= "Fill_parent" android:password= "true" android:text= "Please enter password" android:layout_height= "wrap_content" > </EditText> </LinearLayout> <linearlayo UT android:layout_marginleft= "10px"Android:layout_marginright=" 10px "android:gravity=" center "android:layout_width=" Fill_parent "Android:o rientation= "Horizontal" android:layout_height= "wrap_content" > <textview android:textsize= "8pt" and roid:text= "Confirm Password" android:layout_weight= "0.75" android:layout_width= "Fill_parent" Android : layout_height= "Wrap_content" > </TextView> <edittext android:layout_weight= "0 . "Android:layout_width=" Fill_parent "android:password=" true "android:text=" Please enter the password "android:layout_height=" Wrap_ Content "> </EditText> </LinearLayout> <linearlayout android:layout_marginleft= "10px" android:layout_marginright= "10px" android:gravity= "center" android:layout_width= "Fill_parent" Android:o rientation= "Horizontal" android:layout_height= "wrap_content" > <button android:text= "register" android:textSize= "9p T "android:layout_width=" fill_parent "android:layout_height= "Wrap_content" > </Button> </LinearLayout> <linearlayout android:id= "@+id/btnlogin" android:layout_marginleft= "10px" android:layout_marginright= "10px" android:gravity= "center" android:layout_width = "Fill_parent" android:orientation= "horizontal" android:layout_height= "wrap_content" > <Button android:text= " Login "android:textsize=" 9pt "android:layout_width=" fill_parent "android:layout_height=" wrap_content "> </Butto n> </LinearLayout> </LinearLayout> </LinearLayout>


page associated with background code

The friends who are familiar with MVC know that the page in MVC is separate from the background code, which is the same in Android, and the advantage is that the foreground UI design and background program development are completely separated.

Right-click the package file in the SRC folder to add a background class, such as

After clicking the Finish button, we succeeded in creating a background class, but at this time the background class is not associated with the foreground page, we need to overload the OnCreate method in the class to implement the page association

The overloaded steps are as follows, right-clicking in the class file blank


Click OK to add the successful method.

We add Setcontentview (R.layout.register) to the OnCreate method to associate the foreground page,

The full code is as follows:

public class Register extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {//TODO Auto-generat Ed method Stubsuper.oncreate (Savedinstancestate); Setcontentview (R.layout.register);}}


2. Page Jump

Last article we made a landing page, on the landing page has a registration button, we take a look at the landing page to jump to the registration page. The login page code is as follows:

Package Com.example.helloword;import Android.os.bundle;import Android.app.activity;import android.content.Intent; Import Android.view.menu;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;public class Mainactivity extends Activity {private Button btnregister;// Claim registration button @overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); btnregister= (Button) Findviewbyid (r.id.btnregeister);// Locate the Register button on the page Btnregister.setonclicklistener (new Onclicklistener ()//BIND register button click event {@Overridepublic void OnClick (View arg0)                 {//button jump Intent Intent = new Intent (mainactivity.this,register.class); StartActivity (intent);}});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}

Note: Each time you add a page to an Android project, add the activity to the Androidmainfest.xml code as follows

<application        android:allowbackup= "true"        android:icon= "@drawable/ic_launcher"        android:label= "@ String/app_name "        android:theme=" @style/apptheme ">        <activity            android:name=" Com.example.helloword.MainActivity "            android:label=" @string/app_name ">            <intent-filter>                <action android:name= "Android.intent.action.MAIN"/>                <category android:name= " Android.intent.category.LAUNCHER "/>            </intent-filter>        </activity>                 <activity            android:name= "Com.example.helloword.Register" >        </activity>    </application>

Demo Download: http://download.csdn.net/detail/zx13525079024/8118723



. NET programmer play to Android Development---(4) Register page layout

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.