Android学习笔记——LinearLayout
该工程的功能是实现LinearLayout
以下的代码是MainActivity.java中的代码
package com.example.linearlayout; import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView; public class MainActivity extends Activity { private TextView firstText;
private TextView secondText; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); firstText = (TextView)findViewById(R.id.firstText);
secondText = (TextView)findViewById(R.id.secondText); firstText.setText(R.string.firstText);
secondText.setText(R.string.secondText);
}
}
以下的代码是activity_main.xml中的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" > <!--
android:id 为控件制定相应的ID
android:text 指定控件当中显示的文字
android:gravity 指定控件的基本位置/居中居右等
android:textSize 指定控件的基本位置/居中居右等
android:background 指定该控件所使用的背景色,RGB命名法
android:width 指定控件的宽度
android:height 指定控件的高度
android:padding 指定控件的内边距
android:weight 数字为相应的比例
android:singleLine 设定true为同一行显示
--> <TextView
android:id="@+id/firstText"
android:gravity="center_vertical"
android:textSize="20pt"
android:background="#0000ff"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
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:gravity="center_vertical"
android:textSize="15pt"
android:background="#00ff00"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:paddingLeft="10dip"
android:paddingTop="20dip"
android:paddingRight="30dip"
android:paddingBottom="40dip"
android:layout_weight="2"
android:singleLine="true"
/> </LinearLayout>
以下的代码是string.xml中的代码
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">LinearLayout</string>
<string name="hello_world">Hello world!</string>
<string name="firstText">第一行</string>
<string name="secondText">第二行</string>
</resources>
Android学习笔记——LinearLayout的更多相关文章
- [Android学习笔记]LinearLayout布局,剩余空间的使用
转自:http://segmentfault.com/q/1010000000095725 如果使得一个View占用其父View的剩余空间? 答案是使用:android:layout_weight = ...
- 【转】Pro Android学习笔记(二五):用户界面和控制(13):LinearLayout和TableLayout
目录(?)[-] 布局Layout 线性布局LinearLayout 表格布局TableLayout 布局Layout Layout是容器,用于对所包含的view进行布局.layout是view的子类 ...
- Android学习笔记进阶之在图片上涂鸦(能清屏)
Android学习笔记进阶之在图片上涂鸦(能清屏) 2013-11-19 10:52 117人阅读 评论(0) 收藏 举报 HandWritingActivity.java package xiaos ...
- android学习笔记36——使用原始XML文件
XML文件 android中使用XML文件,需要开发者手动创建res/xml文件夹. 实例如下: book.xml==> <?xml version="1.0" enc ...
- Android学习笔记之JSON数据解析
转载:Android学习笔记44:JSON数据解析 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,为Web应用开发提供了一种 ...
- Pro Android学习笔记 ActionBar(1):Home图标区
Pro Android学习笔记(四八):ActionBar(1):Home图标区 2013年03月10日 ⁄ 综合 ⁄ 共 3256字 ⁄ 字号 小 中 大 ⁄ 评论关闭 ActionBar在A ...
- 【转】 Pro Android学习笔记(四十):Fragment(5):适应不同屏幕或排版
目录(?)[-] 设置横排和竖排的不同排版风格 改写代码 对于fragment,经常涉及不同屏幕尺寸和不同的排版风格.我们在基础小例子上做一下改动,在横排的时候,仍是现实左右两个fragment,在竖 ...
- 【转】 Pro Android学习笔记(二九):用户界面和控制(17):include和merge
目录(?)[-] xml控件代码重用include xml控件代码重用merge 横屏和竖屏landsacpe portrait xml控件代码重用:include 如果我们定义一个控件,需要在不同的 ...
- 【转】Pro Android学习笔记(二三):用户界面和控制(11):其他控件
目录(?)[-] Chronometer计时器控件 倒计时CountDownTimer Switch控件 Space控件 其他控件 Android提供了很多控件,基本上都是view的扩展. Chron ...
随机推荐
- Oracle中可以nologging执行的操作
redo重做日志是Oracle数据库恢复(recovery)的基础:但在很多情况下可以通过禁用重做日志的产生来加速SQL语句的完成,也就是我们所说的可nologging化的操作,这些操作大多是或串行的 ...
- 开发错误记录2 .MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
刚在调试android程序报 导致直接崩了 .MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed ...
- tomcat 实例
现在举一个tomcat应用的例子: 我们现在安装一个jenkins, jenkins的安装方式有两种: 一种是war包的安装方式 另一种是:把下载的安装war包放在tomcat的webapps目录下 ...
- Jenkins_获取源码编译并启动服务(一)
一.安装Jenkins插件(可以手动安装,使用推荐安装容易卡死) 系统管理-->插件管理-->可选插件 Folders Plugin OWASP Markup Formatter Plug ...
- 512M内存编译php出错
make时错误如下 virtual memory exhausted: Cannot allocate memory make: *** [ext/fileinfo/libmagic/apprenti ...
- jar-下载站点
nutch: http://archive.apache.org/dist/nutch/ jarfire: http://cn.jarfire.org/ solr: http://archive.ap ...
- TODO: 图片加载框架ImageLoader的实现
1, 使用三级缓存策略 2, 使用builder模式设置ImagLoager的config
- 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox
介绍背水一战 Windows 10 之 控件(文本类) RichTextBlock RichTextBlockOverflow RichEditBox 示例1.RichTextBlock 的示例Con ...
- C# 时间比较大小
1.时间比较大小 DateTime t1 = new DateTime(100); DateTime t2 = new DateTime(20); ...
- 【转】HTTP中的长连接和短连接分析
1. HTTP协议与TCP/IP协议的关系 HTTP的长连接和短连接本质上是TCP长连接和短连接.HTTP属于应用层协议,在传输层使用TCP协议,在网络层使用IP协议.IP协议主要解决网络路由和寻址问 ...