为了账号安全,请及时绑定邮箱和手机立即绑定

布局管理器

标签:
Android

Android的布局主要有以下几个:
线性布局(LInearLayout)、相对布局(RelativeLayout)、帧布局(FrameLayout)、表格布局(TableLayout)、绝对布局(absoluteLayout)、网格布局(GridLayout)、约束布局(ConstraintLayout)
相对布局中需要注意的两个属性:

android:gravity="center" //控件显示的位置
android:ignoreGravity="@id/tv_1" //某一控件不受影响

相对布局管理器内部类
RelativeLayout.LayoutParams
相对布局的相关属性及其解释:
#####相对于父元素给控件布局
android:layout_centerHrizontal 水平居中
android:layout_centerVertical 垂直居中
android:layout_centerInparent 相对于父元素完全居中
android:layout_alignParentBottom 位于父元素的下边缘
android:layout_alignParentLeft 位于父元素的左边缘
android:layout_alignParentRight 位于父元素的右边缘
android:layout_alignParentTop 位于父元素的上边缘
android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就以父元素做参照物
#####属性值必须为id的引用名“@id/id-name”

    android:layout_below      位于元素的下方 
    android:layout_above      位于元素的的上方 
    android:layout_toLeftOf   位于元素的左边 
    android:layout_toRightOf  位于元素的右边 
    android:layout_alignTop   该元素的上边缘和某元素的的上边缘对齐 
    android:layout_alignLeft  该元素的左边缘和某元素的的左边缘对齐 
    android:layout_alignBottom 该元素的下边缘和某元素的的下边缘对齐 
    android:layout_alignRight  该元素的右边缘和某元素的的右边缘对齐 
给属性赋予像素值
    android:layout_marginBottom      底边缘的距离 
    android:layout_marginLeft           左边缘的距离 
    android:layout_marginRight         右边缘的距离 
    android:layout_marginTop           上边缘的距离

EditText的android:hint :设置EditText为空时输入框内的提示信息

###线性布局(LinearLayout)
线性布局首先要规定排列方向,分别是垂直排列和水平排列:

  android:orientation="horizontal"//水平排列
  android:orientation="vertical" //垂直排列

#####动态修改指定文字颜色:

String text = "获得银宝箱!";  
SpannableStringBuilder style=new SpannableStringBuilder(text);     
style.setSpan(new BackgroundColorSpan(Color.RED),2,5,Spannable.SPAN_EXCLUSIVE_INCLUSIVE);     //设置指定位置textview的背景颜色  
style.setSpan(new ForegroundColorSpan(Color.RED),0,2,Spannable.SPAN_EXCLUSIVE_INCLUSIVE);     //设置指定位置文字的颜色  
textView.setText(style);  

android:layout_weight=“1”//权重 控件剩余部分等分
####登录页面的适用:

<?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"
    tools:context=".LoginActivity">
   <EditText
       android:id="@+id/et_1"
       android:paddingBottom="20dp"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:hint="QQ号/微信号/Email"
       />
  <EditText
      android:id="@+id/et_2"
      android:paddingBottom="20dp"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="请输入密码"
      />
  <Button
      android:layout_marginTop="20dp"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="登录"
      android:textColor="@android:color/white"
      android:background="#ff009688"
    />
  <TextView
      android:layout_marginTop="20dp"
      android:gravity="center"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="登录遇到问题?"
      android:layout_gravity="center"
    />
</LinearLayout>

帧布局:
framelayout.png

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:foreground="@mipmap/ic_launcher"
    android:foregroundGravity="right|bottom"
    tools:context=".FrameActivity">
    <TextView
        android:layout_width="280dp"
        android:layout_height="280dp"
        android:layout_gravity="center"
        android:background="#2196F3"
        android:text="方框1"
        android:textColor="#ffffff"
        />
    <TextView
        android:layout_width="230dp"
        android:layout_height="230dp"
        android:layout_gravity="center"
        android:background="#009688"
        android:text="方框2"
        android:textColor="#ffffff"
        />
    <TextView
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:layout_gravity="center"
        android:background="#9C27B0"
        android:text="方框3"
        android:textColor="#ffffff"
        />

</FrameLayout>

#####表格布局

<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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">
    <!--表格布局下角标从0开始-->
    <!-- android:collapseColumns="1"隐藏第二列-->
    <!--android:stretchColumns="1"设置第二列允许被拉伸-->
    <!--android:shrinkColumns="1"允许第二列被收缩-->
    <TableRow>
        <Button
            android:id="@+id/btn_table"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮1"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮2"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮33333333333333333333333333"
            />
    </TableRow>
    <TableRow>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮4"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮5"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按钮666666666666666666666666666"
            />
    </TableRow>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮666666666666666666666666666"
        />
<TableRow>
    <TextView
        android:gravity="center_horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="账号"
        android:textSize="18sp"
        />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入账号"
        />
</TableRow>

</TableLayout>
点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消