layout_gravity : 设置控件在布局中的位置
gravity :主要设置控件内容在控件中的位置
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<TextView
android:layout_height="wrap_content"
android:text="Account:" />
<EditText
android:id="@+id/account"
android:layout_height="wrap_content"
android:hint="Input your account" />
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:text="Password:" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</TableRow>
<TableRow>
<Button
android:id="@+id/login"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="Login" />
</TableRow>
</TableLayout>
TableRow中的控件是不能指定宽度的。
有一个用于登录的按钮,前两行都有两列,第三行只有一列,这样的表格就会很难看,而且 结构也非常不合理。这时就需要通过对单元格进行合并来解决这个问题,使用 android:layout_span=”2”让登录按钮占据两列的空间,就可以保证表格结构的合理性了
不过从图中可以看出,当前的登录界面并没有充分利用屏幕的宽度,右侧还空出了一块 区域,这也难怪,因为在 TableRow 中我们无法指定控件的宽度。这时使用 android:stretchColumns 属性就可以很好地解决这个问题,它允许将 TableLayout 中的某一列 进行拉伸,以达到自动适应屏幕宽度的作用
所有的对象都继承自view
所有的布局对象都继承自ViewGroup
所有的UI都来自TextView,ImageView,ViewGroup类的子类
好用的导入框架快捷键,爽歪歪 option + enter
按住 control + space 自动提示功能
获取当前环境 getContext()
获取当前ID getId()
自定义个布局控件的过程解析:
首先创建一个xml (new -> XML -> layout xml file),然后里面添加想要的控件,设置好控件的布局关系
创建一个布局文件类(注意是类,所以new -> class ,然后自己去extentds继承布局类),注意初始化方法必须是带两个参数的context,属性set,
其次注意调用方法把自定义的xml加载到类中,LayoutInflater.from(context).inflate(R.layout.title, this);
最后,使用,在main.xml中直接使用创建好的自定义类,直接用前缀.名字.布局类,也就是自定义的xml全路径
res->drawable下面不能有文件夹,只能有文件
创建文件夹必须在在res下面创建,而且必须是资源文件
创建类文件必须在java下面创建,否则创建不成功
创建get和set方法快捷键 control + enter
鼠标放到属性和方法上,按住control键就可以看到文档解释
通俗的说,inflate就相当于将一个xml中定义的布局找出来.
command + shit + p 输入Json -> sublime自动对齐 爽歪歪