Overview of the Android activity layout

Source: Internet
Author: User

Activity Layout Brief

XML- based layouts

Main.xml ( call Project Res/layout/main.xml defined interface element to complete layout display )

<?XML version= "1.0"encoding= "Utf-8"?>
<LinearLayoutxmlns:Android= "Http://schemas.android.com/apk/res/android"
              Android: Orientation= "vertical"
              Android: Layout_width= "Fill_parent"
              Android: Layout_height= "Fill_parent"
><!--linear layout --
    <ImageButton
            Android: ID= "@+id/button1"
            Android: Layout_width= "Wrap_content"
            Android: Layout_height= "Wrap_content"
            Android: Text= "Wrap_content mode"
            Android: src= "@drawable/ic_launcher"
    /><!--to display an image on the button--
    <Button
            Android: ID= "@+id/button2"
            Android: Layout_width= "Fill_parent"
            Android: Layout_height= "Fill_parent"
            Android: Text= "Fill_parent mode"
    /><!--This button is displayed as Fill_parent mode--
    <TextView
            Android: Layout_width= "Fill_parent"
            Android: Layout_height= "Wrap_content"
            Android: Text= "Hello world, myactivity"
    />
</LinearLayout>

based on the layout of the Activity

PackageCOM.EXAMPLE.MYAPP1;

Importandroid.app.Activity;
ImportAndroid.graphics.Color;
ImportAndroid.os.Bundle;
ImportAndroid.widget.TextView;
//The contents of the activity source files generated by the system are as follows

Public classMyActivityextendsActivity {
/**
* Called when the activity is first created.
     */
    @Override
//means overriding this OnCreate method (using Oncreat () to create the appropriate activity, this method is generally necessary;)
The bundle holds the state of the application when it was last closed and can be passed to another activity through one activity
    Public voidOnCreate (Bundle savedinstancestate) {
Super. OnCreate (Savedinstancestate);
TextView tv=NewTextView ( This);
Tv.settext ("Hello");//Set display text
        Tv.settextsize (48.0f);//Set Font size
        Tv.settextcolor (Color.BLUE);//Set Font color
        Setcontentview (TV);The //Statement argument is an instance object name, not an XML layout file


    }
}

Overview of the Android activity 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.