<xml>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
br/>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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.mycompany.helloworld.MainActivity"br/>tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
其中,wrap_content为强制扩充来显示textview中的内容
<MainActivity>
package com.mycompany.helloworld;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {//写方法时继承自Activitybr/>@Override//伪代码,表示方法重写
protected void onCreate(Bundle savedInstanceState) {//Bundle savedInstanceState用于保存状态
super.onCreate(savedInstanceState);
//调用Activity的onCreate方法,和Activity必须搭配使用
setContentView(R.layout.activity_main);//setContentView将Activity与xml可视化文件关联的代码
}
}
原文地址:http://blog.51cto.com/13820071/2131506