Android Studio Development Note one

Source: Internet
Author: User
<span id="Label3"></p><p><p>1.<br>ImageView: A control that displays a picture<br>Property:<br>android:src= "@ path"<br>Android:backgroud= "@ path" serves as background<br>android:backgroud= "#ffffff" color serves as background</p></p><p><p>2.button and ImageButton features:<br>(1) Common features: can be used as a button to generate click events<br>(2) different: button has text property, ImageButton has src attribute<br>(3) Create a noticeable click effect</p></p><p><p>3.onClick Events<br>(1) button and ImageButton all have an onclick event, through their own<br>The. Setonclicklistener (onclicklistener) method to add a click event<br>(2) all controls have an onclick event, not just button and ImageButton have<br>(3) Click on the event of the listener can achieve the Click button after the action of what to Happen.</p></p><p><p> 4. Three ways to listen for event implementations: <br> (1) Implementation of the anonymous inner class <br> (2) implementation of a standalone class <br> (3) implements the interface in a way that implements the <br> Code: <br> activity_main: <br> <?xml version= " 1.0 "encoding=" utf-8 ", <br> <linearlayout xmlns:android=" http://schemas.android.com/apk/res/android "<br> xmlns:tools= "http://schemas.android.com/tools" <br> android:layout_width= "match_parent" <br> Android:layout_height = "match_parent" <br> android:orientation= "vertical" <br> android:paddingbottom= "@dimen/activity_vertical_margin" <br> android:paddingleft= "@dimen/activity_horizontal_margin" <br> android:paddingright= "@dimen/activity_ Horizontal_margin "<br> android:paddingtop=" @dimen/activity_vertical_margin "<br> tools:context=" Com.example.administrator.image.MainActivity "; </p></p><p><p><!--<br>SRC for display picture;<br>Background as background image<br>Orientation represents a layout that can be vertical<br>-<br><!--<br><imageview<br>Android:background= "#cccccc"<br>Android:id= "@+id/imageview1"<br>Android:layout_width= "wrap_content"<br>android:layout_height= "wrap_content"<br>Android:src= "@drawable/img"<br>/><br>-<br><!--<br><imageview<br>Android:id= "@+id/imageview2"<br>Android:layout_width= "match_parent"<br>android:layout_height= "20dp"<br>Android:background= "@drawable/background"<br>/><br>-</p></p><p><p><!--define the name of a button by accessing a string resource<br>android:text= "@string/button_name"<br>-<br><button<br>Android:id= "@+id/button1"<br>Android:layout_width= "wrap_content"<br>android:layout_height= "wrap_content"<br>android:text= "button 1"<br>/><br><button<br>Android:id= "@+id/button2"<br>Android:layout_width= "wrap_content"<br>android:layout_height= "wrap_content"<br>android:text= "button 2"<br>/></p></p><p><p><button<br>Android:id= "@+id/button3"<br>Android:layout_width= "wrap_content"<br>android:layout_height= "wrap_content"<br>Android:src= "@drawable/img"<br>/><br></LinearLayout></p></p><p><p>Mainactivity:<br>Package com.example.administrator.image;</p></p><p><p>Import android.support.v7.app.AppCompatActivity;<br>Import android.os.Bundle;<br>Import android.util.Log;<br>Import android.view.View;<br>Import android.widget.Button;<br>Import android.widget.Toast;</p></p><p><p>public class Mainactivity extends Appcompatactivity {<br>Private Button loginbutton;<br>Private Button loginButton1;<br>Private Button imgbutton;</p></p><p><p>@Override<br>protected void OnCreate (Bundle Savedinstancestate) {<br>Super.oncreate (savedinstancestate);<br>Setcontentview (r.layout.activity_main);<br>/*<br>1. Initialize the currently required control, how to initialize a control?<br>Findviewbyid--returns the object of a view, so it is converted to a button object<br>Findviewbyid how to find the ID of the corresponding view<br>2. Set the listener of the button to implement what we click button to do<br>*/<br>loginbutton= (Button) Findviewbyid (r.id.button1);<br>loginbutton1= (Button) Findviewbyid (r.id.button2);<br>imgbutton= (Button) Findviewbyid (r.id.button3);<br>/*<br>Listener Event Mode: 1. Anonymous inner class</p></p><p><p>Loginbutton.setonclicklistener (new View.onclicklistener () {<br>@Override<br>public void OnClick (View V) {<br>Listen for the action of clicking button in the current OnClick method<br>System.out.println ("my Button was clicked");<br>LOG.I ("tag", "independent Implementation of the onclick event");<br>}<br>});<br>*/</p></p><p><p>/*<br>How to listen to Events: 2. Writing and function of external classes</p></p><p><p>Loginbutton.setonclicklistener (new Myonclicklistener () {<br>@Override<br>public void OnClick (View V) {<br>Calling the onclick of the parent class<br>Super.onclick (v);<br>Toast.maketext (mainactivity.this, "button1 logic to execute", toast.length_long). show ();<br>}<br>});</p></p><p><p>Loginbutton1.setonclicklistener (new Myonclicklistener () {<br>@Override<br>public void OnClick (View V) {<br>Calling the onclick of the parent class<br>Super.onclick (v);<br>Toast.maketext (mainactivity.this, "button2 logic to execute", toast.length_long). show ();<br>}<br>});<br>*/<br>/*<br>Implement listener events by implementing an interface<br>*/<br>}</p></p><p><p>}<br>Onclicklistener is an interface that cannot inherit<br>Class Myonclicklistener implements view.onclicklistener{<br>@Override<br>public void OnClick (View V) {<br>LOG.I ("tag", "onclick Event of the parent class");<br>Let all buttons that use the Click events of the previous external class make an action to change the transparency of the button itself<br>V.setalpha (0.5f);<br>}<br>}</p></p><p><p>Android Studio Development Note one</p></p></span>

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.