Android learning 01

A, Android's UI layout

1. Using XML File Layout

  Writing XML layout files under res / layout directory Android applications:  activity_main.xml 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="38dp"
        android:text="开心消消乐!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.01" />
</androidx.constraintlayout.widget.ConstraintLayout>

 

  In MainActivity.java by introducing the following code:

package com.kevin.happydispear;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);    // 引入布局文件
        Log.d("MainActivity","onCreate execute");   // 使用日志调试
    }
}

  2. Use Java code layout

Guess you like

Origin www.cnblogs.com/kevinOnes1/p/11231159.html