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代码中动态的设置,也可以在布局文件中设置(比较死板)

 import android.os.Bundle;
import android.app.Activity; public class Layout01 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/firstText"
android:text="第一行"
android:gravity="center_vertical"
android:textSize="15pt"
android:background="#aa0000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingTop="20dip"
android:paddingRight="30dip"
android:paddingBottom="40dip"
android:layout_weight="1"
android:singleLine="true"/>
<TextView
android:id="@+id/secondText"
android:text="第二行"
android:gravity="center_horizontal"
android:textSize="15pt"
android:background="#0000aa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="40dip"
android:layout_weight="1"/>
</LinearLayout>

清单文件:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mars.layout01"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="18" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.mars.layout01.Layout01"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>

string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Layout01</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string> </resources>

最新文章

  1. C++随笔:从Hello World 探秘CoreCLR的内部(1)
  2. Rigid motion segmentation
  3. su root 和su - root 的区别
  4. c++对象创建带括号与无括号的区别
  5. Google Kubernetes设计文档之服务篇-转
  6. ASP注入靶机
  7. mysql时该如何估算内存的消耗,公式如何计算?
  8. Objective-C:Block
  9. PLSQL_性能优化系列04_Oracle Optimizer优化器
  10. 深层解析:构建facebook应用商店推荐引擎
  11. Android图片框架---Glide
  12. Button的设置及各种属性
  13. android 有效载荷大图,避OOM
  14. 通过HttpClient来调用Web Api接口,实体参数的传递
  15. Python的html和xml解析库Beautiful Soup
  16. 花店橱窗(flower)
  17. 2015: [Usaco2010 Feb]Chocolate Giving
  18. 修改hosts不必重启 立刻生效
  19. Java核心技术第八章——泛型程序设计(1)
  20. dos3章

热门文章

  1. Java基础系列--ArrayList集合
  2. JAVA 的输入与输出流当中,什么时候该使用字符流?什么时候该使用字节流?
  3. [android] 手机卫士读取联系人
  4. 01-Java基本语法
  5. Java基础——Ajax(一)
  6. idea/ecipse中使用maven集成springmvc相关jar包时候,出错:java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
  7. Maven远程仓库的各种配置
  8. Python全栈学习_day005知识点
  9. Manjaro使用笔记-使用中国源的方法
  10. 小程序和PHP学习笔记 ----- 不定期更新。