Android Notes-4-implement landing page and jump and simple registration page

Source: Internet
Author: User

implement landing page and jump and simple registration pageFirst, let's look at the XML code for the layout login.xml
<span style= "FONT-FAMILY:ARIAL;FONT-SIZE:18PX;" ><?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:background=" @drawable /bkcolor "android:orientation=" vertical "> <linearlayout android:layout_width=" fill_parent "Android oid:layout_height= "50DP" android:background= "@drawable/topbg2" android:gravity= "Center_vertical" Android oid:orientation= "Horizontal" > <button android:id= "@+id/cancel" android:layout_width= "6 5.83DP "android:layout_height=" 30.5DP "android:layout_marginleft=" 10DP "Android:backgroun d= "@drawable/normal_btn" android:text= "@string/cancel" android:textcolor= "#ffffff"/> <       TextView android:id= "@+id/tv_friend_title" android:layout_width= "Wrap_content"     android:layout_height= "50dip" android:layout_weight= "1" android:gravity= "center" and            roid:text= "AppName" android:textcolor= "#ffffff" android:textsize= "20dip"/> <button            Android:id= "@+id/login_in" android:layout_width= "65.83DP" android:layout_height= "30.5DP" android:layout_marginright= "10DP" android:background= "@drawable/normal_btn" android:text= "@s Tring/login_in "android:textcolor=" #ffffff "/> </LinearLayout> <relativelayout Android : id= "@+id/editrel" android:layout_width= "fill_parent" android:layout_height= "wrap_content" > <R Elativelayout android:id= "@+id/accountrel" android:layout_width= "Fill_parent" Android:lay out_height= "Wrap_content" android:layout_margintop= "14DP" android:background= "@drawable/preference_f Irst_item "anDroid:clickable= "true" android:gravity= "center_vertical" > <textview android:id                = "@+id/account" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"                android:padding= "8DP" android:text= "@string/account" android:textcolor= "#000"                Android:textsize= "17sp"/> <edittext android:id= "@+id/accountedittext" Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" Android:lay Out_centervertical= "true" android:layout_marginleft= "20dip" android:layout_torightof= "@id/ac Count "android:background=" @null "android:hint=" @string/account "Android:text            Size= "15sp"/> </RelativeLayout> <relativelayout android:id= "@+id/pwdrel" Android:layout_width= "fiLl_parent "android:layout_height=" wrap_content "android:layout_below=" @id/accountrel "and roid:background= "@drawable/preference_last_item" android:clickable= "true" android:gravity= "Center_ve Rtical "> <textview android:id=" @+id/pwd "android:layout_width=" Wrap_conten T "android:layout_height=" wrap_content "android:padding=" 8DP "android:text=" @                String/pwd "android:textcolor=" #000 "android:textsize=" 17SP "/> <edittext Android:id= "@+id/pwdedittext" android:layout_width= "Fill_parent" android:layou t_height= "Wrap_content" android:layout_centervertical= "true" android:layout_marginleft= "20di P "android:layout_torightof=" @id/pwd "android:background=" @null "Android:hint          = "@string/pwd"      Android:textsize= "15sp"/> </RelativeLayout> </RelativeLayout> <textview Andro Id:id= "@+id/sound_help" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android oid:layout_margintop= "15dip" android:layout_marginleft= "15dip" android:text= "@string/forget_pwd" Android Oid:textcolor= "#29981A"/></linearlayout></span>

  

Let's look at the first line, which is mainly about XML version information and encoding format. The next is the point, the code is written, we can see how the layout of the code is also easy to debug, then this time need to click on the graphical layout below, this is a visual editing window, we write the XML code is what it looks like, You can see it here, so this is very convenient. Basically what is shown here, to the actual operation of the mobile phone is what it looks like, so everyone write a layout style when you have to switch back and forth, adjust the details of the layout depends on this. Let's start by explaining the 5 commonly used layouts: 1. LinearLayout (Linear layout) 2.RelativeLayout (relative layout) 3.AbsoluteLayout (absolute layout) 4.TableLayout (table layout) 5.FrameLayout (single frame layout) Today I will only use two of them, then I will only talk about two of them, at least I now do so many projects, the most used is actually the first two, basically can complete most of the layout. Talking about here my brother asked: so many layouts, the layout seems to have what is the length of the height, there are many properties oh, how to remember to live AH? This layout is not good, the page map is not good to draw ah. I said: "Yes, but who asks you to remember so much?" Now start, what to use to check what, remember the basis of the attributes can be, the other or need to use the time to check, so as to quickly start from scratch, each of you ask why go deep, that can not. A lot of things now speak and do not understand, when the time has come, do not say you also understand. However, after the completion of the search for information and thinking is essential. And the most important thing is to do hands-on experiments, their own to hit the code, is the kingly. Okay, Sanda back to our layout code, first we came to a linearlayout as the overall layout of the tone, the next thing is written to this big linearlayout above. Then here's a description, the layout can be nested, meaning that linearlayout below can also nest other layouts or linearlayout. Specifically how, no hurry, we slowly step-by-step. The brother immediately asked: xmlns:android= http://schemas.android.com/apk/res/androidWhat do you mean by this sentence? I said: I do not know, so, to check, oh this is the XML namespace, with him, you can alt+/as a hint, prompted you to enter what, what should not be entered, what is right, what is wrong, can also be understood as a grammar file.   Or a grammar-judging device or something. Android:layout_width= "Fill_parent"android:layout_height= "Fill_parent"Android:background= "@drawable/bkcolor"android:orientation= "Vertical"The first sentence is actually set this width, then the value we fill is filled with this width, we can also alt+/to see what properties, then will use the other second sentence is actually the same set height. The third sentence is the entire background we directly quoted a color, the same you can refer to the picture you put in the drawable-hdpi below, in fact, it is equivalent to us or some app when the background image of the launch. The next sentence is what is arranged in the space below this layout, we are here in the way of vertical sorting, meaning that the following components are arranged from top to bottom, of course, if you choose horizontal is left to right in the way of arrangement. Well the big background we set up, in fact, this time what all wood has, but you will see the background color changed. Next we will add buttons, input boxes, text and so on. First of all this time we have a mind that the layout is divided, not all things are a word a word, a button to write a button. Here we take a look at the top of the Titile bar as a piece, the middle of the account password input box as a piece, the bottom of the forgotten password for a piece. Then we can know that there should be three, then the first one, according to the first block, the general development process is, first of all, the United States trade union design the entire page style, and then cut the diagram, we will be based on that as a reference to the layout of our content. The top piece according to his design we see is three content, 2 button,1 a textview. And it's arranged horizontally, so what can we do with just nesting a linearlayout and arranging it? Said before, of course, with horizontal, it will automatically from the left to the right of the arrangement of the same is not introduced, but also set the size of the button, where the size is based on the art of cutting the picture to calculate, there is a conversion tool is the pixel conversion dip conversion tool android:id= "@+id/cancel"This is to add an ID number for this button, it is easy to find this button in the code, for this button to write the corresponding function, here also posted in the loginactivity to find this button code bar.        Button Cancel; Cancel= (Button) Findviewbyid (r.id. Cancel); Cancel.setonclicklistener ( NewOnclicklistener () {@Override Public voidOnClick (View v) {//here do what you want to do with this button you want to do.  }        }); android:layout_marginleft= "10DP"The meaning of this sentence is far from the left margin, the general 10-15DP is the best looking distance, anyway, all the unity is good. Also there is the text content of the button we all write to strings.xml inside, through android:text= "@string/cancel"This way to invoke, the advantage of doing this is that in case there is a change in the future without one by one to change. The previous article page describes, here is the actual use.  Let's write. Android:textcolor= "#ffffff"This sentence is the text color, here is black, as for other colors we can go to check. All the others are very much the same, I believe you must have a higher IQ than my brother, he can make it, you little genius must be able to extrapolate, or I am not insulting you?  Say too much will be beaten. android:layout_weight= "1"Of course, this is still to say, this is a weight in this linearlayout, equivalent to the whole divided into several, I set the purpose of 1 here is to center the display of this textview, while the remaining two buttons for the remaining space, similar to textview accounted for two parts, Each of the other buttons takes one copy. Or you can try another way to achieve this effect, maybe I did it wrong. Brother: Why did you do it? Can you do it in any other way? Me: I don't know, you remember what I told you is probably wrong, so you have to have the spirit of doubt, while you can experiment with other methods. Trailer: Something happened in the back to prove it, so I was wrong. If I am wrong, please correct me, I change, I am a good boy, not the kind you pointed out to me, I do not change, you come to hit me ah that kind of person! Trailer: Something happened in the back to prove it, so I was wrong. If I am wrong, please correct me, I change, I am a good boy, not the kind you pointed out to me, I do not change, you come to hit me ah that kind of person! Next talk about Relativelayout, that is, the following key points in the implementation of the account password this layout is called relative layout, then there must be a relative object at this time my brother asked: What is the difference between @+id/name and @id/name? How to use it? I answer: actually has the plus sign that is adds an ID, the other one is refers to that ID. Okay, then the relative layout would look like this code android:layout_torightof= "@id/account"It means to put the space on the ID of the account of the right side of the space, of course, there are many parameters, but also can be placed on the left, placed below, put on top and so on, you can enter the android: after the ctrl+/to see. In the following article I will make a detailed description of the parameters which are specific. Continue to explain when you use it. The basic layout is almost done. To explain the Jump method before the reference to the picture, You may have seen the end format of some of the pictures in drawable-hdpi. 9.png description of a picture is made using the tools of Android, the purpose is to make the picture with a smaller volume at the same time stretching the picture will not be a variant, we first understand that there is such a thing. Next is the jump related code is mainly the use of intent, when to jump? We clicked on the landing when the jump, my code is as follows: Button loginbtn = (button) Findviewbyid (r.id. login_in); Loginbtn.setonclicklistener ( NewOnclicklistener () {@Override Public voidOnClick (View v) {// TODOauto-generated method Stub//Here you can determine whether the account password is correct, here let everyone own test hands-on Thank you if the account password is the admin 123456 success//otherwise prompt login Land failure, everyone try it, I directly jump here, did not verify//This is a direct jump to mainactivity Intent Intent = NewIntent (); Intent.setclass (loginactivity. This, Mainactivity. class);            StartActivity (Intent); }}); At the same time to leave a job is, everyone to get the content of the edit box, and then the account for the admin, password 123456 as the correct account, to determine whether the input is correct, the success of the jump, failed on the pop-up hint. Intent is responsible for the action of an operation in the application, the action involves data, the additional data is described, Android according to this intent description, is responsible to find the corresponding component, the intent passed to the calling component, and complete the call of the component. Intent can be passed with parameters, and bundles can be bound. These late will use we continue to speak, here we are simply to achieve the jump, SetClass is to tell the computer from which class to which class to go, and then call the Startactiviy () method can be successfully jump. Article reproduced in Source: http://blog.csdn.net/jkingcl/article/details/10989773

Android Notes-4-implement landing page and jump and simple registration page

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.