Component Inheritance diagram:
Component Common Properties:
1)Layout_width: The width of the component, generally only three values wrap_content, fill_parent (used in the old version), Match_parent, but he is not the only one that controls the width of the element
2)layout_height: The height of the component, generally only three values wrap_content, fill_parent (used in the old version), Match_parent, but he is not the only element to control height
3) Width: The width of the component, he is not the only one that controls the width of the element, and he and layout_width together determine the width of the component
4) Height: The height of the assembly, he is not the only element of control height, he and layout_height together determine the height of the component
5) Text: textual content
6)Hint: When the text content is empty, the content specified by this element is displayed
7)Singleline: If the text content is too long, then the text content is not fully displayed, replace with Sheng ellipsis
8)Gravity: The content alignment within the component, he and android:layout_gravity have an essential difference, android:layout_gravity refers to their own in the parent component alignment
9)Visibility: Whether the component is displayed,visible default value: Display; invisible: not shown, but occupies space; gone: not displayed and does not occupy space
TextSize: Text size, text-related properties have text beginning as TextStyle
Autolink: Text content is in the form of email, phone number, etc., when the user is near the text is to display the hyperlink form
Note: The difference between layout_width and width (layout_height and height):
1) both determine the size of the component
2) Width does not work when Layout_width is set to fill_parent or match_parent, because it is already the maximum value and is determined by the layout_width.
3) When Layout_width is set to Wrap_content, width and wrap_content after the system is calculated, who is the width of the large who decides the final width of the component.
1 TextView
The
Text control mainly includes TextView controls and
<textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:textSiz E= "30SP" android:width= "200DP" android:height= "300DP" android:visibility= "visible" Android:gra vity= "center" android:autolink= "email" android:singleline= "false" android:hint= "@string/app_name" android:text= "@string/maxtext"/>
2 EditText
text controls primarily include TextView controls and EditText controls,EditText classes inherit from TextView classes,EditView is a text field that can be edited, like the type of input in HTML is text, of course you can set his type. Using Android:inputtype to set the text type, this property is very important.
<edittext android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:inputTy Pe= "Textpassword" android:textsize= "30sp" android:width= "200DP" android:height= "300DP" Android : visibility= "visible" android:gravity= "center" android:autolink= "email" android:singleline= "false" android:hint= "@string/app_name"/>
3 Button
One of the most commonly used button-push components, he is a subclass of TextView, and his own indirect sub-class is also rich, mainly: CheckBox, RadioButton, ToggleButton, learning button The most important is not the layout, but his event monitoring , how to handle the listener events are as follows:
<button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:textSize= "30sp" android:width= "200DP" android:height= "300DP" android:visibility= "visible" Android:gravi ty= "center" android:autolink= "email" android:singleline= "false" android:hint= "@string/app_name" android:text= "@string/login"/>
The first way:
Need to note:
1) Themethod specified by the onclick must be declared in the activity, and in the public void, the parameter must have a view type.
2) manifest file does not have to be set this way, it just means register activity
The activity has the following settings:
public class Mainactivity extends Activity {@Override protected void onCreate (Bundle savedinstancestate) {//TODO auto- Generated method stub super.oncreate (savedinstancestate); This.setcontentview (r.layout.mainlayout); } public void ClickMe (view view) {Toast.maketext (this, "Hello World", Toast.length_short). Show ();}}
Layout in the following settings:
<button android:id= "@+id/btn" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android: Textsize= "30SP" android:width= "200DP" android:height= "300DP" android:visibility= "visible" android:gravity= "center" android:autolink= "Email" android:singleline= "false" android:hint= "@string/app_name" android:text= "@string/login" android:onclick= "ClickMe"/>
The following settings are in the manifest file:
<activity android:name= "com.leagsoft.moon.activity.MainActivity" > <intent-filter> &L T;action android:name= "Android.intent.action.MAIN"/> <category android:name= " Android.intent.category.LAUNCHER "/> </intent-filter> </activity>
The second way:
Need to note:
1) do not need to use the OnClick method to specify the event listener processing, if the OnClick method is specified, he will be overwritten by the following way.
2) The activity needs to implement the interface Onclicklistener, and then register in the button we specified.
3) It is more recommended to use this method.
The activity has the following settings:
public class mainactivity extends Activity { private Button btn; @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); This.setcontentview (r.layout.mainlayout); btn = (Button) Findviewbyid (R.ID.BTN); btn.setonclicklistener (New btnclickimpl ()); } class btnclickimpl implements onclicklistener{ @Override public void onclick (View arg0) { toast.maketext (mainactivity.this, "Hello world", Toast.length_short). Show (); } } }
Layout and manifest configuration files are basically the same.
4 Toast
It is used primarily for informational cues, similar to the alert in JavaScript, but more humane than alert.
Toast.maketext (Context, "Hello World", Toast.length_short). Show ();
Android Nineth Lesson--ui Components