Learning steps and key points
- Ui Layout
- Main UI elements
- Main buttons and events
- Screen jump
- Dialog Box
I. Android UI Layout
This section mainly refers to this person's blog for a little bit of sorting. For the original text, see: Original Text
1.1 linear layout (Linearlayout)
An important parameter for this layout isAndroid: Orientation = "horizontal" (horizontal display). In total, 2 elements are vertically displayed as"Vertical ".
Reference code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="horizontal"></LinearLayout>
1.2 relative layout (Relativelayout)
This layout is very easy to use. You can quickly locate your UI elements to the desired position and important parameters as needed.
Android: layout_below: "Ida corresponding to the button". This code is relative to the lower part of button. You can practice other operations on the top, bottom, and right sides.
Reference Code
<? XML version = "1.0" encoding = "UTF-8"?> <Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <progressbar Android: id = "@ + ID/progressbar1" style = "? Android: ATTR/progressbarstylelarge "Android: layout_width =" wrap_content "Android: layout_height =" wrap_content "Android: Rule =" true "Android: layout_centerhorizontal =" true "Android: layout_margintop = "60dp"/> <textview Android: Id = "@ + ID/textview1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"Android: layout_below = "@ + ID/progressbar1"Android: layout_centerhorizontal = "true" Android: layout_margintop = "52dp" Android: text = "loading..." Android: textappearance = "? Android: ATTR/textappearancelarge "/> </relativelayout>
Reference Image instances
1.3 List View (List View)
Ignore it for the time being. It will be further summarized later.
IIMain UI elements
The android. View. View class is the basis class of Widgets. Most Android UI elements are contained in Android. widgets. The inheritance relationships of each class are shown in figure
2.1 text (textview)
It is a simple text display, and the background obtains the text content code:
TextView viewme=(TextView) findViewById(R.id.textView1);viewme.setText(“test”);
Button 2.2)
The button is also relatively simple. The next section focuses on the event
2.3 image (imageview)
The core of imageview is the source of the image. There are three methods. The Code is as follows:
img.setImageResource(resId)img.setImageBitmap(bm)img.setImageURI(uri)
Progress bar 2.4
Obtain the maximum value getmax () and set the length progresscire. setprogress (100 );
2.5 drop-down button (spinner)
It mainly sets the content source:
Spinner spinnerdemo = (spinner) findviewbyid (R. id. spinner1); arrayadapter <string> adapter = new arrayadapter <string> (this, android. r. layout. simple_spinner_item); adapter. add ("red"); adapter. add ("blue"); spinnerdemo. setadapter (adapter );
You can also create an array content file in the values folder, for example:
<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <string-array name = "Colors"> <item> Red </item> <item> orange </item> <item> yellow </item> <item> when using green </item> <item> blue </item> <item> purple </item> </string-array> </resources>, use R. array. colors
2.6 textswitcher)
Temporarily ignore and supplement later.
Three-button event
Scenario settings: click the button and the text box displays Hello word!
Event code implementation:
// Add a button event button = (button) findviewbyid (R. id. button1); // set the listener button. setonclicklistener (New button. onclicklistener () {public void onclick (view v) {textview viewme = (textview) findviewbyid (R. id. textview1); viewme. settext ("Hello word! "); }});
Four-screen jump
First, prepare two page activities. Here there are a and B2 pages (A is the home page), and then add a new configuration in androidmanifest. XML (page a already exists by default ).
<activity android:name=".B"></activity>
Because only one master startup page exists, B does not contain
<activity android:name=".A" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
Event code in:
// Jump to button buttongo = (button) findviewbyid (R. Id. button2); buttongo. setonclicklistener (New button. onclicklistener () {public void onclick (view v ){
Intent intent = new intent ();
Intent. setclass (reaboxactivity. This, imgshowactivity. Class );
Startactivity (intent );
Finish ();
}});}
5. Pop-up box
The dialog box class is Android. App. Dialog, which is created through the Android. App. alertdialog. Builder class.
There is also a simple pop-up box implementation, the Code is as follows:
import android.widget.Toast;Toast.makeText(this,“hello”, Toast.LENGTH_SHORT).show();