gravity和layout_gravity的区别
android:gravity与android:layout_gravity。他们的区别在于:android:gravity用于设置View组件的对齐方式,而android:layout_gravity用于设置Container组件的对齐方式
 
线性布局是最常用的布局线性布局在xml文件中使用<LinearLayout>来定义
线性布局可以分为水平和垂直的方向的布局,可以通过android:orientation=“vertical”来定义方向,该属性可以有horizontal和vertical两个方向。(线性布局才有)

android:id —— 为控件指定相应的ID
android:text —— 指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xml文件当中的字符串
android:grivity —— 指定控件的基本位置,比如说居中,居右等位置(控件里面的内容位置)
android:textSize —— 指定控件当中字体的大小
android:background —— 指定该控件所使用的背景色,RGB命名法
android:width —— 指定控件的宽度
android:height —— 指定控件的高度
android:padding* —— 指定控件的内边距,也就是说控件当中的内容
android:layout_margin*——指定控件的外边距,也就是说控件跟父控件之间的距离
android:sigleLine —— 如果设置为真的话,则将控件的内容在同一行当中进行显示

 
 

控件的布局,可以再java代码中动态的设置,也可以在布局文件中设置(比较死板)

  1. import android.os.Bundle;
  2. import android.app.Activity;
  3.  
  4. public class Layout01 extends Activity {
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.main);
  9. }
  10. }

布局文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <TextView
  8. android:id="@+id/firstText"
  9. android:text="第一行"
  10. android:gravity="center_vertical"
  11. android:textSize="15pt"
  12. android:background="#aa0000"
  13. android:layout_width="fill_parent"
  14. android:layout_height="wrap_content"
  15. android:paddingLeft="10dip"
  16. android:paddingTop="20dip"
  17. android:paddingRight="30dip"
  18. android:paddingBottom="40dip"
  19. android:layout_weight="1"
  20. android:singleLine="true"/>
  21. <TextView
  22. android:id="@+id/secondText"
  23. android:text="第二行"
  24. android:gravity="center_horizontal"
  25. android:textSize="15pt"
  26. android:background="#0000aa"
  27. android:layout_width="fill_parent"
  28. android:layout_height="wrap_content"
  29. android:padding="40dip"
  30. android:layout_weight="1"/>
  31. </LinearLayout>

清单文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.mars.layout01"
  4. android:versionCode="1"
  5. android:versionName="1.0" >
  6.  
  7. <uses-sdk
  8. android:minSdkVersion="4"
  9. android:targetSdkVersion="18" />
  10.  
  11. <application
  12. android:allowBackup="true"
  13. android:icon="@drawable/ic_launcher"
  14. android:label="@string/app_name"
  15. android:theme="@style/AppTheme" >
  16. <activity
  17. android:name="com.mars.layout01.Layout01"
  18. android:label="@string/app_name" >
  19. <intent-filter>
  20. <action android:name="android.intent.action.MAIN" />
  21.  
  22. <category android:name="android.intent.category.LAUNCHER" />
  23. </intent-filter>
  24. </activity>
  25. </application>
  26.  
  27. </manifest>

string.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3.  
  4. <string name="app_name">Layout01</string>
  5. <string name="action_settings">Settings</string>
  6. <string name="hello_world">Hello world!</string>
  7.  
  8. </resources>

控件布局_LinearLayout的更多相关文章

  1. 控件布局_LinearLayout的嵌套

    import android.os.Bundle; import android.app.Activity; public class Layout03 extends Activity { @Ove ...

  2. CSharpGL(26)在opengl中实现控件布局/渲染文字

    CSharpGL(26)在opengl中实现控件布局/渲染文字 效果图 如图所示,可以将文字.坐标轴固定在窗口的一角. 下载 CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入( ...

  3. React-Native 之控件布局

    Nodejs 一度将前端JS 推到了服务器端,而15年FB的React-Native RN再一次将JS 推到了移动端的开发浪潮中.RN的优势这里不再重复,它是我们这些习惯了服务端.web端开发,而又不 ...

  4. 运用 BoxLayout 进行 Swing 控件布局

    摘自http://www.cnblogs.com/fnlingnzb-learner/p/6008572.html 运用 BoxLayout 进行 Swing 控件布局 对于初学 Java Swing ...

  5. 学习笔记<4>初步控件布局

    一.控件布局基本概念 指控制控件在Activity当中的位置.大小.颜色以及其他控件样式属性 二.控件布局两种方法 1.使用布局文件完成控件布局(eclipse可视化拖拽控件实现) 2.在JAVA代码 ...

  6. 利用wtl的CDialogResize自动调整atl ActiveX控件布局

    前言 利用atl 开发activex控件时,如果使用atl复合控件时,acitvex控件上的界面元素不会自动改变大小,如果自己在OnSize中处理每个子控件的布局是一件非常麻烦的事,我们可以借助wtl ...

  7. QT学习记录之控件布局

    作者:朱金灿 来源:http://blog.csdn.net/clever101 想到控件布局就会想到Windows编程中要实现对话框上的控件的合理布局是一件多么艰难的事情.对此QT提出了一个很方便的 ...

  8. CPF 入门教程 - 控件布局(六)

    CPF netcore跨平台桌面UI框架 系列教程 CPF 入门教程(一) CPF 入门教程 - 数据绑定和命令绑定(二) CPF 入门教程 - 样式和动画(三) CPF 入门教程 - 绘图(四) C ...

  9. Android入门(六):Android控件布局属性全解

    第一类:属性值为true或falseandroid:layout_centerHrizontal 水平居中 (Hrizontal表示水平)android:layout_centerVertical 垂 ...

随机推荐

  1. 利用cordova打包H5混合app

    1.首先布置jdk环境,下载jdk(http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...

  2. JavaWeb学习 (二十八)————文件上传和下载

    在Web应用系统开发中,文件上传和下载功能是非常常用的功能,今天来讲一下JavaWeb中的文件上传和下载功能的实现. 对于文件上传,浏览器在上传的过程中是将文件以流的形式提交到服务器端的,如果直接使用 ...

  3. [转]group by 后使用 rollup 子句总结

    group by 后使用 rollup 子句总结 一.如何理解group by 后带 rollup 子句所产生的效果 group by 后带 rollup 子句的功能可以理解为:先按一定的规则产生多种 ...

  4. 正则表达式--C#正则表达式的符号及例子

    正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串”用来表达对字符串的一种过滤逻辑. C#中经常会遇到要查找某一个字 ...

  5. c# Datatable导出Excel

    using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; ...

  6. Spark练习代码

    1.scalaWordCount package com._51doit.spark.day1 import org.apache.spark.rdd.RDDimport org.apache.spa ...

  7. Kite(几何+镜面对称)

    C. Kite Time Limit: 1000ms   Case Time Limit: 1000ms   Memory Limit: 65536KB   Vova bought a kite co ...

  8. 移动端meta整理

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...

  9. 【CSS学习】--- 背景

    一.前言 元素的背景区域包括:元素的内容.内边距和边框区域. CSS中用于设置背景的属性有: background-color 设置背景颜色 background-image 设置背景图片 backg ...

  10. 2017-07-29 中文代码示例教程之Java编程一天入门

    Java编程一天入门 v0.0.1 alpha 共享协议 本作使用署名-非商业使用-禁止演绎协议共享. 前言 Java入门代码用中文写(举例如下)更能被新手理解. 由于至今没有看到类似教程, 在此抛砖 ...