Android使用线性布局(LinearLayout)

首先我们得知道,一个 Android 程序是由一个或多个 Activity 组成的,Activity 是一个 UI 容器,它本身不在用户界面中显示出来。其中类 View 起了一个重要的作用,View 是一个最基本的 UI 类,几乎所有的 UI 组件都是继承自View 而实现的。TextView 的使用格式如下:
android.view.View
其主要功能如下:

  1. 为指定的屏幕矩形区域存储布局和内容

  2. 处理尺寸和布局,绘制,焦点改变,翻屏,按键、手势

  3. widget 基类
    线性布局即 LinearLayout 布局,是 Android 屏幕中常用的布局方式,是一个 ViewGroup
    以线性方向显示它的子视图(view)元素,即垂直地或水平地。

    如何使用线性布局

  4. 首先在Android studio下创建一个安卓应用。

  5. 创建好之后编辑mian.xml文件,线性布局可分垂直线性和水平线性。我们先试试水平线性。

  6. 在main.xml下插入以下代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"    android:layout_height="match_parent"	android:orientation="horizontal">	<Button		android:layout_weight="1"		android:id="@+id/mainButton"		android:text="按钮1"		android:layout_width="wrap_content"		android:layout_height="wrap_content"	/><Button		android:layout_weight="1"		android:id="@+id/mainButton1"		android:text="按钮2"		android:layout_width="wrap_content"		android:layout_height="wrap_content"	/>	<Button				android:layout_weight="1"	
```		android:id="@+id/mainButton2"				android:text="按钮3"	
		android:layout_width="wrap_content"
			android:layout_height="wrap_content"/>		<Button		android:layout_weight="1"		android:id="@+id/mainButton3"		android:text="按钮4"		android:layout_width="wrap_content"	android:layout_height="wrap_content"	/>		</LinearLayout>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会写Java的小疯子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值