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 ...
随机推荐
- PHP自学链接收藏
PHP之道 laravist Sublime Text 3
- Java面试常考知识点
1. 什么是Java虚拟机?为什么Java被称作是“平台无关的编程语言”? Java虚拟机是一个可以执行Java字节码的虚拟机进程.Java源文件被编译成能被Java虚拟机执行的字节码文件. Jav ...
- 开发错误记录11:git报错 fatal:open /dev/null or dup failed: No such file or directory
今天在自己的的电脑上装了git,没成想运行报错: 重装了几次git ,都不行,电脑上没有装github桌面版; 后来在网上查到了方法,反映这是系统的问题: null是比较特殊的系统文件,它实际上是为操 ...
- 【POJ 1743】Musical Theme
后缀数组求了height,模板题啦啦啦 #include<cstdio> #include<cstring> #include<algorithm> using n ...
- 【BZOJ 2843】极地旅行社
复习一下$LinkCutTree$的模板. #include<cstdio> #include<cstring> #include<algorithm> #defi ...
- 强联通 poj 2762
t个样例 (注意清零) n个点m条边 有向; 任意2点是否能从a->b或者b->a; Yes No #include<stdio.h> #include<algo ...
- mnsday2t1
枚举每个数的因子,然后该因子数量+1,最后扫描一遍,如果该因子数量小于等于m且该因子在1-n之间就输出 复杂度:枚举因子:O(n^1/2*m) 输出答案 : 大概是O(m*?) 一个不知道的数字 #i ...
- dede使用方法----调用导航
在这里,极力推荐学习dede的朋友们观看老李的零基础织梦仿站系列课程的视频,讲的超级棒的~~ 网址链接是:http://www.dede888.com/15daylessons.html. 好了,言归 ...
- const、static、extern三个关键字
默认情况下,C语言的全局变量是全世界都可以访问的,也就是全局变量可以跨文件访问. extern可以引用全局变量 例如,如果有一个全局变量int money = 100;extern int money ...
- Casually have a look
1. 用红盘子吃饭能助你减肥.教授告诉我们:“红色是一种原始的危险信号,它同时也会使盘中的食物看上去不那么诱人,所以你也会吃得更少.” 2. 要减肥请关电视.教授说:“如果你需要减肥,请在吃饭时把电视 ...