android基础-界面代码
2016-12-16 13:38
141 查看
android 的界面 都是.xml文件 存放在 res/layout里
要做界面首先需要懂得LinearLayout线性布局,有两种格式
android:orientation="vertical"
android:orientation="horizontal"
指定宽度和高度的 wrap_parent match_parent //这里就不讲fill_parent,只要理解为match_parent的功能比fill_parent更好就行了
1.首先看图理解下什么是父节点和子节点
![](http://img.blog.csdn.net/20161216134015735?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjg3Mzg0MTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
wrap_parent :子节点有多大,父节点就有多大(父节点会根据子节点的大小调节自己的大小)
match_parent:父容器有多大,子节点就有多大。(父节点不会因为子节点的大小二人改变自己的大小)
另外,如果不想用这些关键词,你还可以利用android:layout_width="500dp"
可以用dp单位自己指定大小!
这里是代码解释:
<?xml version="1.0"
encoding="utf-8"?>
//这句是必不可少的指定编码格式
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
//默认的不用理会
android:orientation="vertical"
//这里是决定这线性布局是横着的还是竖着的
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
//这里定义的是它对应的java文件
android:layout_width="match_parent"
//这里定义的是它的宽度 和高度
android:layout_height="match_parent"
//这下面的暂时不用管,因为你如果要增加一个组件的话只要定义它的宽和高就可以让他正常的显示了
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.asus.uidesigner.MainActivity">
</LinearLayout>
接下来再告诉你可以调节占有界面比例的解释
先看效果
![](http://img.blog.csdn.net/20161216134102560?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjg3Mzg0MTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_weight="9"
//指定比例 sum
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.asus.uidesigner.MainActivity">
<Button
android:layout_weight="3"
//指定占有界面的比例
android:layout_height="match_parent"
android:layout_width="0dp"
//宽度的比例要将原来你设定的比例设置为0dp
android:text="y"
android:textSize="30dp"/>
<Button
android:layout_weight="3"
//指定占有界面的比例
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="s"
android:textSize="30dp"/>
<Button
android:layout_weight="3.09"
//指定占有界面的比例
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="p"
android:textSize="30dp"/>
</LinearLayout>
要做界面首先需要懂得LinearLayout线性布局,有两种格式
指定宽度和高度的 wrap_parent match_parent //这里就不讲fill_parent,只要理解为match_parent的功能比fill_parent更好就行了
1.首先看图理解下什么是父节点和子节点
wrap_parent :子节点有多大,父节点就有多大(父节点会根据子节点的大小调节自己的大小)
match_parent:父容器有多大,子节点就有多大。(父节点不会因为子节点的大小二人改变自己的大小)
另外,如果不想用这些关键词,你还可以利用android:layout_width="500dp"
可以用dp单位自己指定大小!
这里是代码解释:
<?xml version="1.0"
encoding="utf-8"?>
//这句是必不可少的指定编码格式
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
//默认的不用理会
android:orientation="vertical"
//这里是决定这线性布局是横着的还是竖着的
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
//这里定义的是它对应的java文件
android:layout_width="match_parent"
//这里定义的是它的宽度 和高度
android:layout_height="match_parent"
//这下面的暂时不用管,因为你如果要增加一个组件的话只要定义它的宽和高就可以让他正常的显示了
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.asus.uidesigner.MainActivity">
</LinearLayout>
接下来再告诉你可以调节占有界面比例的解释
先看效果
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_weight="9"
//指定比例 sum
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.asus.uidesigner.MainActivity">
<Button
android:layout_weight="3"
//指定占有界面的比例
android:layout_height="match_parent"
android:layout_width="0dp"
//宽度的比例要将原来你设定的比例设置为0dp
android:text="y"
android:textSize="30dp"/>
<Button
android:layout_weight="3"
//指定占有界面的比例
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="s"
android:textSize="30dp"/>
<Button
android:layout_weight="3.09"
//指定占有界面的比例
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="p"
android:textSize="30dp"/>
</LinearLayout>
相关文章推荐
- Android基础:代码中实现界面动态布局
- Android-NDK开发之基础--Android JNI实例代码(一)-- 在JNI中执行Java方法--C/C++调用Java
- Android-NDK开发之基础--Android JNI实例代码(三)-- 在JNI中构造和实例化Java类
- [Android UI界面] 你导入工程的时候遇没遇到过,工程里面的xml文件就有代码,没有可见视图界面,并且写代码的时候还联想不出来
- android基础——界面布局(二) 线性布局
- android基础——界面布局(一)
- Android(OPhone) 学习笔记 - 代码基础
- Android-NDK开发之基础--Android JNI实例代码(二)-- 获取/设置类的域或者说属性字段
- Android-NDK开发之基础--Android JNI实例代码(三)-- 在JNI中构造和实例化Java类
- android布局基础及范例(一):QQ登陆界面设计
- Android-NDK开发之基础--Android JNI实例代码(四)-- JNI中的异常处理实例代码
- Android-NDK开发之基础--Android JNI实例代码(四)-- JNI中的异常处理实例代码
- 【Android开发基础】应用界面主题Theme使用方法
- 在android里如何代码调用系统短信发送界面
- Android-NDK开发之基础--Android JNI实例代码(一)-- 在JNI中执行Java方法--C/C++调用Java
- Android-NDK开发之基础--Android JNI实例代码(二)-- 获取/设置类的域或者说属性字段
- Android JAVA 语言基础例子代码
- Android下无界面后台发送彩信代码
- Android-NDK开发之基础--Android JNI实例代码(四)-- JNI中的异常处理实例代码
- Android-NDK开发之基础--Android JNI实例代码(三)-- 在JNI中构造和实例化Java类