一些xml中的标签定义
一、 AndroidStudio中的线性布局(LinearLayout)多用于按钮的水平或垂直排列
二、LinearLayout常用属性
- orientation:布局中组件的排列方式
android:orientation=“vertical”(组件垂直排列)
android:orientation=“horizontal”(组件水平排列)
2、gravity:控制组件所包含的子元素的对齐方式
3、**layout_gravity:**控制该组件在父容器中的对其方式
4、layout_width:布局的宽度,一般不直接写数字
通常android:layout_width=“match_parent”(填满容器的意思)
**layout_height:**布局的高度,
通常android:layout_height=“match_parent”
5、id:为该组件设置一个资源id,在java文件中可以通过findViewById(id)找到该组件
6、background:为该组件设置一个背景图片,或者直接用颜色覆盖
7、wrap_content:和组件本身大小适配
match_parent:和组件适配
三、TextView控件基本属性:
TextView控件就是可以写在中的
1、**layout_width=“match_parent”**控件的宽度是适应父容器的
layout_height=“wrap_content”,控件的高度与控件本身大小适配
2、TextView中也有:
id
background
gravity
text
四、EditText是一个常用的控件,也是一个比较重要的组件,是用户跟安卓应用进行数据传输的窗户
1、ems用法:
android:ems=“10”,设置TextView或EditText的宽度为10个字符的宽度
五、BMI的整体代码:
1、BMI计算器的布局文件,
activity_main.xml,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<!--更改布局为线性布局LinearLayout
水平布局:
垂直布局:vertical
-->
<!--这个最外面的Linearout是整个大页面的布局-->
<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"
tools:context=".MainActivity"
android:orientation="vertical"
>
<!--第一组身高组件-->
<!--wrap_content:和组件本身大小适配-->
<!--match_parent:和父窗口适配-->
<!-- 下边这个TextView是第一行 “身高”这两个字的布局 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv1"
android:text="身高"
/>
<!--EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,
可以说它是用户跟Android应用进行数据传输的窗户-->
<!--android:ems ="10"设置TextView或者Edittext的宽度为10个字符的宽度-->
<!-- 下面这个EditView是用户输入身高为多少的那个横线区域 -->
<EditText
android:id="@+id/shengao"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
/></