LinearLayout
package com.example.testjava1;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class LinearLayoutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_linear_layout);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:weightSum="1"
android:padding="10dp"
android:gravity="end"
tools:context=".LinearLayoutActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入联系人" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入主题" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="start"
android:hint="请输入内容" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发送" />
</LinearLayout>
注意
layout_gravity :控件在父布局中的对齐方式,接收参数与 gravity 相同。
gravit:元素排列方向。
weightSum:布局等分比例。