安卓APP布局——简单认识

一、简述

  • 六大基本布局(布局可以理解为画布),View(主件)被ViewGroup(主件的群)所继承。
  • 按键,文本等都是放在布局上的
    在这里插入图片描述

二、具体实现

  • 默认用的是相对布局 RelativeLayout
  • 布局,格式
    布局,文本框,按键
<RelativeLayout 代码内容,设置相关参数>  //开头 
</RelativeLayout>   //结尾 多了一个/

<TextView	//文本框
	/>

<Button 	//按键
	/>
  • 代码意思
    每个布局都有的3句,背景,宽,高,id
xmlns:android="http://schemas.android.com/apk/res/android"	//版本
xmlns:tools="http://schemas.android.com/tools"	//工具位置
tools:context=".MainActivity" 

android:background="#ff0000"	//布局背景,可以是颜色,可以是图片
android:background="@drawable/bx1"	//图片放在res下的drawable-hdpi 高分辨率

android:layout_width="500dp"	//宽,match_parent跟屏幕一样宽,wrap_content图片有多大就显示多大
    
android:layout_height="200dp"	//高,match_parent跟屏幕一样高

android:id="@+id/bx1"	//创建id
android:layout_below="@id/bx1"	//显示在bx1的下面

三、代码演示

  • 一个布局下放文本框和按键
    在这里插入图片描述
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="500dp"
    android:layout_height="200dp"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#ff0000"	
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="小伟" android:id="@+id/textView1"/>
    <Button android:id="@+id/button1"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Button" 
        android:layout_below="@+id/textView1" 
        android:layout_centerHorizontal="true" 
        android:layout_marginTop="38dp"/>

</RelativeLayout>
  • 显示2张图片,一个大布局下放2个小布局,布局1创建id,布局2显示在布局1的下方(不创id,会盖住,只显示出来一个图)
    在这里插入图片描述
<RelativeLayout 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"
    tools:context=".MainActivity" >

    <RelativeLayout 
        android:id="@+id/bx1"
        android:layout_width="match_parent"
    	android:layout_height="400dp"
    	android:background="@drawable/bx1"
        ></RelativeLayout>
    
    <RelativeLayout 
        android:layout_below="@id/bx1"
        android:layout_width="match_parent"
    	android:layout_height="400dp"
    	android:background="@drawable/bx2"
        ></RelativeLayout>

</RelativeLayout>

师承上官可编程 —— 陈立臣

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

dz小伟

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

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

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

打赏作者

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

抵扣说明:

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

余额充值