Android ѧϰ01

匿名 (未验证) 提交于 2019-12-02 23:51:01

一、Android的UI布局方式

1.使用XML文件布局

  在Android应用的res/layout目录下编写XML布局文件: 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> 

  在MainActivity.java中,通过如下代码引入:

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.使用Java代码布局

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!