http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 2612|回复: 6

[新手开发之旅] Android新手开发之旅-基本布局方式(一)

[复制链接]
发表于 2018-11-28 17:05:39 | 显示全部楼层 |阅读模式
一、简介
      开发一个APP,有一个漂亮的界面是很重要的,因为用户第一眼看到的就是我们的界面,界面好看了才能更加吸引大家来使用,并且写逻辑代码之前一般也要先搭好布局,所以我们要能熟练的使用各种布局方式和各个组件。
      本次要说的是如下六种基本布局方式:
      1、线性布局(LinearLayout)
      2、相对布局(RelativeLayout)
      3、帧布局(FrameLayout)
      4、表格布局(TableLayout)
      5、网格布局(GridLayout)
      6、绝对布局(AbsoluteLayout)

      其中,表格布局是线性布局的子类。网格布局是android 4.0后新增的布局


      本次先来了解
线性布局(LinearLayout)

二、使用方式
     1、线性布局(LinearLayout)
            最常用的一种布局方式,具有如下属性:

            "android: orientation"               控制子控件排列方向,属性值垂直(vertical)和水平(horizontal),默认水平方向

            ”android:layout_width"            宽度,属性值wrap_content,match_parent或者fill_parent,也可以自己设置数值,单位dp

            "android:layout_height"           高度属性值wrap_content,match_parent或者fill_parent,也可以自己设置数值,单位dp

            "android:layout_weight"          权重,用来分配当前控件在剩余空间的大小,使用权重一般要把分配该权重方向的长度设置为 零,比如在水平方向分配权重,就把width设置为零。

            "android:layout_gravity"          相对于父控件位置

            "android:gravity"                     子控件的位置,常用属性值有center、center_vertical(垂直居中)、center_horizontal(水平居中)、top、 bottom、left、right等

          示例代码:
                        
[XML] 纯文本查看 复制代码
<?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="com.company.helloworld.firstapplication.MainActivity">

    <!-- 上边LinearLayout -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <!-- 控件1 -->
        <TextView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@color/colorAccent"
            android:gravity="center"
            android:text="1" />

        <!-- 控件2 -->
        <TextView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="right"
            android:background="@color/colorPrimary"
            android:gravity="center"
            android:text="2" />
    </LinearLayout>

    <!-- 分割线 -->
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorPrimary" />

    <!-- 下边LinearLayout -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal">

        <!-- 控件3 -->
        <TextView
            android:layout_width="50dp"
            android:layout_height="100dp"
            android:background="@color/colorAccent"
            android:gravity="center_vertical"
            android:text="3"
            android:textSize="18sp" />

        <!-- 控件4 -->
        <TextView
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:background="@color/colorPrimary"
            android:gravity="center_horizontal"
            android:text="4"
            android:textSize="18sp" />
    </LinearLayout>

</LinearLayout>

            效果图:

             QQ截图20181128152915.png

            注意:

            当orientation为vertical时,子控件设置android:layout_gravity="center_vertical"或者自身设置android:gravity="center_vertical"是无效的。
            同样当orientation为horizontal时,子控件设置android:layout_gravity="center_horizontal"或者自身设置android:gravity="center_horizontal"是无效的





























1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2018-11-28 17:10:10 | 显示全部楼层
我只是路过打酱油的。
发表于 2018-11-28 17:15:44 | 显示全部楼层
感恩无私的分享与奉献
发表于 2018-11-28 17:26:55 | 显示全部楼层
强烈支持楼主ing……
发表于 2018-11-28 17:27:14 | 显示全部楼层
图文并用,楼主辛苦喽
发表于 2018-11-28 18:43:10 | 显示全部楼层
这个背景看着很不错 下次可以试试
发表于 2018-11-28 19:47:47 | 显示全部楼层
收藏,以后学习用。
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-18 12:01

© 2014-2021

快速回复 返回顶部 返回列表