安卓学习笔记(嵌套布局和ImageButton按钮和约束布局管理器)

嵌套布局

嵌套原则

在这里插入图片描述

<?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"
    tools:context=".chat"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <ImageView
            android:id="@+id/icon1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_alignParentLeft="true"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginBottom="10dp"
            android:src="@drawable/yi" />
        <TextView
            android:id="@+id/name1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="招牌男@MT"
            android:textColor="#576B95"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/icon1"
            />
        <TextView
            android:id="@+id/name2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="祝大家逢考必过,最终拿到offer"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:minLines="3"
            android:layout_toRightOf="@+id/icon1"
            android:layout_below="@+id/name1"
            />

        <TextView
            android:id="@+id/time1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/name2"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="-14dp"
            android:layout_toRightOf="@+id/icon1"
            android:minLines="3"
            android:text="昨天"
            android:textColor="#9A9A9A" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <ImageView
            android:id="@+id/icon2"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_alignParentLeft="true"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginBottom="10dp"
            android:src="@drawable/er" />
        <TextView
            android:id="@+id/name3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="春暖花开"
            android:textColor="#576B95"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/icon2"
            />
        <TextView
            android:id="@+id/name4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="不要在最美好的青春,荒废了自己!"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:minLines="3"
            android:layout_toRightOf="@+id/icon2"
            android:layout_below="@+id/name3"
            />

        <TextView
            android:id="@+id/time2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/name4"
            android:layout_marginLeft="6dp"
            android:layout_marginTop="-9dp"
            android:layout_toRightOf="@+id/icon2"
            android:minLines="3"
            android:text="两小时前"
            android:textColor="#9A9A9A" />
    </RelativeLayout>



</LinearLayout>

显示效果图

在这里插入图片描述

imageButton和Button区别

在这里插入图片描述

文本框组件

一般在设置文字的时候是在values中的string中去定义
在这里插入图片描述

单行文本框

如果一段文字太长,但是想让其只在一行显示可以使用 android:singleLine="true"来实现

约束布局管理器

使用约束布局的原因

在这里插入图片描述

约束布局的优点

在这里插入图片描述

位置约束

在这里插入图片描述
这些代码可以在可视化中拖拽中自动生成
在这里插入图片描述

圆形定位

参照控件,需要有半径,两个空间中点之间的连线与Y轴的夹角,
在这里插入图片描述
尺寸约束
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

William_Tao(攻城狮)

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

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

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

打赏作者

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

抵扣说明:

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

余额充值